0
votes

I'm trying to plot using Gnuplot in C and so far I'm half succeeding following another thread, but couldn't find anywhere how to go one step beyond.

My code for plotting goes as follows:

char * commandsForGnuplot[] = {"set title \"Probability evolution\"", "plot 'data.temp' with linespoints", "set xlabel \"beta probability\"", "set ylabel \"Fraction of sick individuals\""};
    FILE * temp = fopen("data.temp", "w");
    FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
    for (i=0; i < NB; i++){
    fprintf(temp, "%lf \n", B[i]); 
    }
    for (i=0; i < 4; i++){
    fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); 
    }

Everything is showed correctly except for the xlabel and ylabel, so this part must be wrong:

"set xlabel \"beta probability\"", "set ylabel \"Fraction of sick individuals\""

Does anyone know how to set it properly?

Also, how can I set the size of these labels and the title?

Thanks a million!

2

2 Answers

0
votes

The plot part is what actually creates the plot. Everything you set afterwards, is ignored:

char * commandsForGnuplot[] = {
    "set title \"Probability evolution\"", 
    "set xlabel \"beta probability\"",
    "set ylabel \"Fraction of sick individuals\"",
    "plot 'data.temp' with linespoints"
};
-1
votes

Thanks a lot, that worked!

So following that lead I'd like to modify the axis ranges, but now again there seems to be something wrong in the code:

 char * commandsForGnuplot[] = {
        "set title \"Probability evolution\"font \"Helvetica, 20\"",
        "set xrange \"[100:1000]\"",         
        "set xlabel \"Time steps\"font \"Helvetica, 15\"", 
        "set ylabel \"Fraction of sick individuals\"font \"Helvetica, 15\"", 
        "plot 'data.temp' with linespoints"

Gnuplot doesn't seem to get the way the xrange is typed, how should I adapt it?

Thanks again!