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