【问题标题】:gnuplot window does not showgnuplot 窗口不显示
【发布时间】:2021-01-14 07:02:23
【问题描述】:

我正在尝试使用 C 接口初始化 gnuplot,遵循 this 示例:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
void plot(float xValues[], float yValues[], int NUM_POINTS) {
    char* commandsForGnuplot[] = { "set title \"TITLEEEEE\"", "plot 'data.temp'", "fflush(gnuplotPipe)" };
    FILE* temp = fopen("data.temp", "w");
    FILE* gnuplotPipe = _popen("gnuplot -persistent", "w");
    int i;
    for (i = 0; i < NUM_POINTS; i++)
    {
        fprintf(temp, "%lf %lf \n", xValues[i], yValues[i]); //Write the data to a temporary file
    }

    fclose(temp);

    for (i = 0; i < 3; i++)
    {
        fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
    }
}

void main(){
    float a[] = {0, 1, 2, 5, 8};
    float b[] = {0, 1, 2, 3, 4};
    plot(a, b, 5);
}

由于某种原因,情节没有出现。我应该更正什么?

编辑

发现提示窗口显示如下信息:

"'gnuplot' 未被识别为内部或外部命令, 可运行的程序或批处理文件。”

编辑2 以下@theozh添加了gnuplot.exe的路径并解决了问题

【问题讨论】:

  • 在使用 gnuplot 之前,您可以尝试关闭 temp 文件
  • @Damien,已做出更正。查看更新...
  • gnuplot.exe 的路径添加到Windows 环境变量PATH 或在_popen() 命令中提供gnuplot.exe 的完整路径。
  • 在使用之前,您应该始终检查任何FILE * 变量的NULL 值。

标签: c windows gnuplot


【解决方案1】:

根据 SO“规则”,再次将我的评论作为答案:cmets 中没有答案。否则,这个问题将继续显得没有答案。

要么

  • gnuplot.exe的路径添加到Windows环境变量PATH

  • 在您的_popen() 命令中提供gnuplot.exe 的完整路径

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2011-11-10
    • 2011-09-15
    • 2022-01-27
    • 2016-03-29
    • 1970-01-01
    相关资源
    最近更新 更多