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

标签 c plot gnuplot

我已经能够在运行程序时使用 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/

相关文章:

matlab - 在 Matlab 中绘制 x、y、z 范围内的四个变量 u = f(x, y, z)

r - 如何从 R 中的矢量图形制作自定义绘图符号

c++ - 使用 C++ 中的对象字段数据在 Visual Studio 2013 中创建图表

date - x 轴上的 Gnuplot 日期/时间

c++ - Cuda:访问冲突写入位置 0x0000000000000000

c - 使用简单预处理器定义的内存映射地址

c - C 中的链表遇到字符串问题

c - 从队列打印的程序改为打印一个数字

r - R 中一百万个观测值的 Kmeans - 绘制集群时遇到的问题

if-statement - 如何读取脚本中不规则编号的数据文件来制作gnuplot图像?