Menu

#25 Multiple plots (+real time plotting)

None
closed
nobody
None
5
2019-06-03
2007-03-19
No

Hi there,

I realized the following function to realize a simple 1-D vector plot (for temporal series and so on).

########## BEGIN CODE ##########
void plot( float* y_T, int N )
{
PLFLT *x = new PLFLT[N];
PLFLT *y = new PLFLT[N];
for (int i = 0; i < N; i++) {
x[ i ] = i;
y[ i ] = y_T[ i ];
}

// Initialize PLplot.
plstream *pls = new plstream();
plsdev( "gcw" ); /* USE GNOME OUTPUT WINDOW LIBRARY BY DEFAULT */
plscolbg (255,255,255); /* SET THE GRAPH BACKGROUND */
pls->init(); /* INITIALIZE THE WIDGET */
pls->font(2); /* CHOOSE THE FONT */
pls->adv(0); /* advance to next page */

pls->vpor( 0.1,0.9,0.1,0.9 ); /* position of graph inside window */
pls->wind( 0, N, 0, 400); /* set axis x-range, y-range (matlab axis command)*/

// Draw axis with their style
plrgb(0,0,0); pls->box("bnstg", 0.0, 0, "bnstvg", 0.0, 0);

// Plot ampl vs freq.
plcol0(1); c_plpoin( N, x, y, 'o' ); /* plot stem graph */
plrgb(1,0,1); pls->line( N, x, y ); /* plot line junction points */

// Put labels on.
plrgb(0,0,0); pls->mtex("b", 3.2, 0.5, 0.5, "Frequency");
plrgb(0,0,0); pls->mtex("l", 5.0, 0.5, 0.5, "Amplitude (dB)");

delete[] x;
delete[] y;
delete pls;
}
########## END CODE ##########

There are two principal main issues: the first is that if i call this function multiple times, only 1 X window is opened and anyway the content of the plot is always the one of the first function call.

A second issue (partially related to this one) is that I can't obtain a real time plot of a 1D time-varying vector (think for example the Fourier spectrum of a time varying signal).

Hope that you can help me with this.
Thanks, Andrea

Discussion

  • James Dishaw

    James Dishaw - 2007-03-20

    Logged In: YES
    user_id=875337
    Originator: NO

    I haven't used Plplot with C++, however, I think your problem is that you are missing calls to pleop, plbop, and pladv. I use Plplot extensively to display data in realtime as my code is running. After each data frame, I issue the following commands (in Fortran, but the conversion to C++ should be straightforward) before plotting the next data frame

    CALL pleop
    CALL plbop
    CALL pladv(plots(plotID)%subpage)

    The subpage is used if I have multiple plots in the same viewer.

     
  • Arjen Markus

    Arjen Markus - 2007-03-20

    Logged In: YES
    user_id=400048
    Originator: NO

    The type of plot you want for the real-time data is known as a strip chart.
    Use the functions plstripa(), plstripb() and plstripc() for this.
    See example x17.cc for an idea of how to go about.

    As for your question regarding multiple windows, you can achieve that by
    using multiple PLstreams, and initialise each one via a call to plinit(),
    but I have never used that way, so there may be more involved.

    Note: you may want to post further questions on the PLplot mailing list
    (plplot-devel@lists.sourceforge.net or plplot-general@lists.sourceforge.net)
    where much more people hang out.

     
  • Alan W. Irwin

    Alan W. Irwin - 2019-06-03
    • status: open --> closed
    • Group: -->
     
  • Alan W. Irwin

    Alan W. Irwin - 2019-06-03

    Closed (too old).

     

Log in to post a comment.