Plplot绘制随时间变换的动态图

来源:互联网 发布:sql中的exists 编辑:程序博客网 时间:2024/06/08 19:27

这是一张随时间变换的动态图像,用到的plot函数有:

// Create 1d stripchart,可同时绘4条函数
    void stripc( PLINT *id, const char *xspec, const char *yspec,
                 PLFLT xmin, PLFLT xmax, PLFLT xjump, PLFLT ymin, PLFLT ymax,
                 PLFLT xlpos, PLFLT ylpos,
                 bool y_ascl, bool acc,
                 PLINT colbox, PLINT collab,
                 const PLINT colline[], const PLINT styline[], const char *legline[],
                 const char *labx, const char *laby, const char *labtop );

// Add a point to a stripchart.
    void stripa( PLINT id, PLINT pen, PLFLT x, PLFLT y );
// Deletes and releases memory used by a stripchart.
    void stripd( PLINT id );

程序代码如下:

#include "plc++demos.h"#ifdef PL_HAVE_UNISTD_H# include <unistd.h>#else# ifdef PL_HAVE_POLL#  include <poll.h># endif#endif#ifdef PL_USE_NAMESPACEusing namespace std;#endifplstream *pls;static PLINT pl_errcode= 0;static char  errmsg[160]= "";int main( int argc, const char ** argv ){PLINT           id_StripChart,  nsteps = 1000;bool            autoy, acc;PLFLT           y1, y2, y3, y4, init_ymin, init_ymax, xlab, ylab;PLFLT           t, init_tmin, init_tmax, tjump, dt, noise;PLINT           colbox, collab, colline[4]={0}, styline[4]={0};const char      *legline[4] ;// plplot initializationpls = new plstream();// Parse and process command line arguments.pls->parseopts( &argc, argv, PL_PARSE_FULL );// Specify some reasonable defaults for ymin and ymax// The plot will grow automatically if needed (but not shrink)init_ymin = -0.1;init_ymax = 0.1;// Specify initial tmin and tmax -- this determines length of window.// Also specify maximum jump in t// This can accomodate adaptive timestepsinit_tmin  = 0.;init_tmax  = 10.;tjump = 0.3;      // percentage of plot to jump// Axes options same as plbox.// Only automatic tick generation and label placement allowed// Eventually I'll make this fanciercolbox     = 1;collab     = 3;styline[0] = colline[0] = 2;      // pens color and line stylestyline[1] = colline[1] = 2;styline[2] = colline[2] = 2;styline[3] = colline[3] = 2;legline[0] = "sin";                       // pens legendlegline[1] = "";legline[2] = "";legline[3] = "";xlab = 0.; ylab = 0.25;   // legend positionautoy = true;             // autoscale yacc   = true;             // don't scrip, accumulate// Initialize PLplot.pls->sdev("qtwidget");pls->init();pls->adv( 0 );pls->vsta();// Register our error variables with PLplot// From here on, we're handling all errors herepls->sError( &pl_errcode, errmsg );pls->stripc( &id_StripChart, "bcnst", "bcnstv",init_tmin, init_tmax, tjump, init_ymin, init_ymax,xlab, ylab,autoy, acc,colbox, collab,colline, styline, legline,"t", "", "Strip chart demo" );if ( pl_errcode ){cout << errmsg << endl;delete pls;exit( 1 );}// Let plplot handle errors from here onpls->sError( NULL, NULL );autoy = false; // autoscale yacc   = true;  // accumulate/// This is to represent a loop over time// Let's try a random walk processy1 = y2 = y3 = y4 = 0.0;dt = 0.1;for ( PLINT n = 0; n < nsteps; n++ ){t     = (double) n * dt;y1    = sin( t * M_PI / 18. );// There is no need for all pens to have the same number of// points or beeing equally time spaced.pls->stripa( id_StripChart, 0, t, y1 );}// Destroy strip chart and it's memorypls->stripd( id_StripChart );delete pls;return 0;}
vs2010工程地址:plplot_time
参考文献:http://plplot.sourceforge.net/examples.php?demo=17&lbind=C%2B%2B

0 0