Save chart as png in gnuplot and C

I managed to use gnuplot to plot the graphs at the start of my program, but now I want to write the graphs to files. The following code opens a graph and creates a png, but the png does not open (Gimp says it is damaged). Admittedly, I really do not understand the code I wrote because it was taken from fragments on the Internet. Does anyone know what happened? All I want to do is save my scatter plot as 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; } 
+4
source share
2 answers

Instead, you want set terminal png .

+4
source

Why not use MathGL (GPL graphics), which can have its own export to PNG / EPS / SVG / ... and can do this even in the console (i.e. without X)?

-1
source

All Articles