gnuplot window 不显示

gnuplot window does not show

我正在尝试使用 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);
}

不知为何,剧情没有出现。我应该纠正什么?

编辑

发现提示window显示如下信息:

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

编辑2 跟随@theozh 将路径添加到 gnuplot.exe 并解决了问题

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

两者都

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

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