【问题标题】:How to use gnuplot from within C program to plot graph如何在 C 程序中使用 gnuplot 绘制图形
【发布时间】:2014-10-06 15:01:27
【问题描述】:

我正在尝试从 C 程序 (Windows 7) 中绘制图表 我维护了一个图形点数组,比如 x[] 和 y1[]、y2[] 和 y3[]。我想为固定的 x 点绘制多个 y 点。 如何在我的程序中使用 gnuplot 绘制图形?

【问题讨论】:

  • 你正在进入一个痛苦的世界,但stackoverflow.com/questions/3521209/…有一条路
  • 我已经尝试使用上面链接中的代码示例。但似乎管道不适用于 Windows 系统。运行程序后,它会打开一个输出窗口,但没有出现任何图表。

标签: c graph gnuplot


【解决方案1】:

不是最优雅的解决方案,但这应该可行:

int main(int argc, char **argv){
    FILE * temp = fopen("data.temp", "w");
    FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
    for(Iterate over your array so that you create another exact temporal array){

        float a, b, c;

        x = something;
        y1 = something;
        y2 = something;
        y3 = something;

        fprintf(temp, "%d %d %d %d \n", x, y1, y2, y3);
    }

    fprintf(gnuplotPipe, "(here whatever you want to tell gnuplot to do) i.e plot 'data.temp' using 1:2 with lines, etc");    

    return 0;
}

您也可以这样做:

int plot(){
    system("gnuplot -p -e \"(Here put whatever you would put in gnuplot as if you were ploting manually)\"");
    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    相关资源
    最近更新 更多