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

这是一张随时间变换的动态图像,用到的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_NAMESPACE
using namespace std;
#endif
plstream *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 initialization

	pls = 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 timesteps

	init_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 fancier

	colbox     = 1;
	collab     = 3;
	styline[0] = colline[0] = 2;      // pens color and line style
	styline[1] = colline[1] = 2;
	styline[2] = colline[2] = 2;
	styline[3] = colline[3] = 2;

	legline[0] = "sin";                       // pens legend
	legline[1] = "";
	legline[2] = "";
	legline[3] = "";

	xlab = 0.; ylab = 0.25;   // legend position

	autoy = true;             // autoscale y
	acc   = 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 here

	pls->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 on

	pls->sError( NULL, NULL );

	autoy = false; // autoscale y
	acc   = true;  // accumulate/

	// This is to represent a loop over time
	// Let's try a random walk process

	y1 = 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 memory
	pls->stripd( id_StripChart );
	delete pls;
	return 0;
}
vs2010工程地址:plplot_time
参考文献:http://plplot.sourceforge.net/examples.php?demo=17&lbind=C%2B%2B

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值