我已经能够在运行程序时使用 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;
}
最佳答案
您需要 set terminal png
代替。
关于c - 在 gnuplot 和 C 中将绘图另存为 png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7293032/