Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3102

set parameters in gnuplot using c++ source code

Newsgroups comp.graphics.apps.gnuplot
Date 2015-10-10 02:45 -0700
Message-ID <cd5f3d6a-2f92-4dd3-908b-1d80a44812bd@googlegroups.com> (permalink)
Subject set parameters in gnuplot using c++ source code
From Marcello Chiurazzi <chiurazzi.marcello@gmail.com>

Show all headers | View raw


Hi I'm trying to plot some vectors using gnuplot from a c++ source code.I already read a question about how to interface c++ with the gnuplot. This is the source code:


 int main()
{

    char * commandsForGnuplot[] = {"set title \"Trajectory_ARM\"","plot 'data.temp' with linespoints"};
    double xvals[NUM_POINTS] = {1.0, 2.0, 3.0, 4.0, 5.0};
    double yvals[NUM_POINTS] = {5.0 ,3.0, 1.0, 3.0, 5.0};
    FILE * temp = fopen("data.temp", "w");
    /*Opens an interface that one can use to send commands as if they were typing into the
     *     gnuplot command line.  "The -persistent" keeps the plot open even after your
     *     C program terminates.
     */
    FILE * gnuplotPipe = popen ("gnuplot -persistent", "w");
    int i;
    for (i=0; i < NUM_POINTS; i++)
    {
        fprintf(temp, "%lf %lf \n", xvals[i]  , yvals[i]); //Write the data to a temporary file
    }

    for (i=0; i < NUM_COMMANDS; i++)
    {
    fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
    }
    return 0;
}



The problem is:

if I have a new vector of 5 points(A) and I want to have in the same plot A and xvals in respect of yvals?
How I should modify my code? In this case I would like to plot A and xvals with two different colors.

Thanks in advance!

Back to comp.graphics.apps.gnuplot | Previous | Next | Find similar


Thread

set parameters in gnuplot using c++ source code Marcello Chiurazzi <chiurazzi.marcello@gmail.com> - 2015-10-10 02:45 -0700

csiph-web