Plplot绘制简单2D函数图

  Plplot是一款开源、跨平台的绘图函数库,具有多种语言接口,可用于某些科学计算的图形显示,官网网站为:http://plplot.sourceforge.net/

本篇要显示一张如下的图片:


程序源码如下:

#include "plc++demos.h"

#ifdef PL_USE_NAMESPACE
using namespace std;
#endif
plstream         *pls;
#define NSIZE  101

void plot0();//绘图函数

int main(int argc, const char** argv)
{
	pls = new plstream();

	// Parse and process command line arguments
	pls->parseopts( &argc, argv, PL_PARSE_FULL );

	// Initialize plplot
	pls->sdev("qtwidget");//输出图像通过qt widget显示
	//pls->sdev("bmpqt");//如果要保存图像为bmp格式,启用该设置
	pls->init();

	plot0();
	// In C++ we don't call plend() to close PLplot library
	// this is handled by the destructor
	delete pls;
	return 0;
}

void plot0()
{
	PLFLT x[NSIZE], y[NSIZE],y1[NSIZE];
	PLFLT xmin = 0., xmax = 1., ymin = 0., ymax = 100.;
	int   i;

	// Prepare data to be plotted.
	for ( i = 0; i < NSIZE; i++ )
	{
		x[i] = (PLFLT) ( i ) / (PLFLT) ( NSIZE - 1 );
		y[i] = ymax * x[i] * x[i]* x[i];
		y1[i] = ymax * x[i] * x[i];
	}
	// Create a labelled box to hold the plot.
	pls->env( xmin, xmax, ymin, ymax, 0, 0 );
	pls->lab( "x", "y=100 x#u3#d", "Simple PLplot demo of a 2D line plot" );

	// Plot the data that was prepared above.
	pls->line( NSIZE, x, y );
}
程序执行后输出图像如下:



程序的vs2010工程地址:Plot_sample

参考文献:http://plplot.sourceforge.net/examples.php?demo=00&lbind=C%2B%2B

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值