1
votes

I've managed to create some code which will continuously send data points from a C program to gnuplot to show evolution of a time dependent Schrodinger equation. This is the function I've made which is iterated in a loop which updates the WF[] values each time: (Both x[] and WF[] are 1d)

void gnuprint(FILE *gp, double x[], int N)
{     
    int i;
    fprintf(gp, "plot '-' with lines\n");

    for (i=0; i<N; i++){fprintf(gp, "%g %g\n", x[i],WF[2*i+1]);}
    fflush(gp);
    fprintf(gp, "e\n");  
}

What I really want to do next is plot the imaginary points on the same plot which are next to the real in the array: x[i], WF[2*i+2]

If I simply just add a

fprintf(gp, "%g %g\n", x[i],WF[2*i+2]); //The imaginary values

into the loop, when 'with lines' specified, the two plots link together (plot points join up). Using dots solves this but I would like both plots to be separately linked with lines and hopefully different colours. Can someone help?

This is the form of the plot i'd like:

enter image description here

1

1 Answers

0
votes

Data which is piped to gnuplot can be used only once. So, if you want to have two plots, with different colors, you must use '-' twice and then send your data sets one after the other, separated by an e:

void gnuprint(FILE *gp, double x[], int N)
{     
    int i;
    fprintf(gp, "plot '-' with lines, '-' with lines\n");

    for (i=0; i<N; i++){fprintf(gp, "%g %g\n", x[i],WF[2*i+1]);}
    fflush(gp);
    fprintf(gp, "e\n");

    for (i=0; i<N; i++){fprintf(gp, "%g %g\n", x[i],WF[2*i+2]);}
    fflush(gp);
    fprintf(gp, "e\n");  
}