在gnuplot和C中将绘图另存为png

在gnuplot和C中将绘图另存为png,c,plot,gnuplot,C,Plot,Gnuplot,我已经能够在运行程序时使用gnuplot绘制图形,但现在我想将图形写入文件。下面的代码打开一个绘图并创建一个png,但png没有打开(Gimp说它已损坏)。诚然,我并不真正理解我所写的代码,因为它是从网上的片段中提取的。有人知道怎么了吗?我想做的就是能够将我的散点图保存为png #include <iostream> #include "gnuplot_i.h" #include <math.h> using namespace std; int main() { d

我已经能够在运行程序时使用gnuplot绘制图形,但现在我想将图形写入文件。下面的代码打开一个绘图并创建一个png,但png没有打开(Gimp说它已损坏)。诚然,我并不真正理解我所写的代码,因为它是从网上的片段中提取的。有人知道怎么了吗?我想做的就是能够将我的散点图保存为png

#include <iostream>
#include "gnuplot_i.h"
#include <math.h>
using namespace std;

int main() {
 double average_distance[5] = {1, 3, 5, 2, 4};
 double x_coord[5] = {1, 2, 3, 4, 5};
 gnuplot_ctrl* h1 = gnuplot_init();
 gnuplot_setstyle(h1, "points");
 gnuplot_cmd(h1, "set output 'test-plot-1.png'");
 gnuplot_plot_xy(h1, x_coord, average_distance, 5, "plot");
 gnuplot_cmd(h1,"set terminal x11" );
 sleep(400);
 return 0;
} 
#包括
#包括“gnuplot_i.h”
#包括
使用名称空间std;
int main(){
双平均_距离[5]={1,3,5,2,4};
双x_坐标[5]={1,2,3,4,5};
gnuplot_ctrl*h1=gnuplot_init();
gnuplot_setstyle(h1,“点”);
gnuplot_cmd(h1,“设置输出‘test-plot-1.png’”);
gnuplot_plot_xy(h1,x_坐标,平均距离,5,“plot”);
gnuplot_cmd(h1,“设置端子x11”);
睡眠(400);
返回0;
} 

您希望
改为设置终端png

为什么不使用(GPL绘图库),它可以本机导出为png/EPS/SVG/。。。即使在控制台中也可以这样做(即不使用X)?

谢谢您的回复。我已经做了更改,但仍然无法打开png文件:(好的,我找到了。我必须在set output命令之前添加set terminal png