本文在一幅图中显示两张子图,可更换图片背景颜色,绘图颜色,线型和线宽,图例如下:
源程序如下:
#include "plc++demos.h"
#ifdef PL_USE_NAMESPACE
using namespace std;
#endif
plstream *pls;
#define NSIZE 101
void plot0();//绘图函数
void plot1();//绘图函数
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");//设置输出驱动
//pls->sdev("bmpqt");//设置输出驱动
pls->scolbg(255,255,255);//设置背景为白色
//pls->init();
pls->star(2,1);//一幅图中显示2*1幅子图
plot0();
plot1();
// In C++ we don't call plend() to close PLplot library
// this is handled by the destructor
delete pls;
return 0;
}
void plot0()
{
pls->col( Red );
pls->env( 0., 1., 0., 1., 0, 0 );
pls->col( Grey );
pls->lab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );
PLFLT x[6], y[6];
for ( int i = 0; i < 6; i++ )
{
x[i] = .2 * i;
y[i] = x[i] * x[i];
}
pls->col( Red );
pls->poin( 6, x, y, 2 );//绘制点,最后一个参数表示点的类型
pls->col( DeepBlue );
pls->width(2);//设置线宽
pls->lsty(1);//设置线性,1-8可选
//pls->mtex("b",0,0,0,"y=x");
pls->line( 6, x, y );
}
void plot1()
{
pls->col( Red );
pls->env( 0., 1., 0., 1., 0, 0 );
pls->col( Grey );
pls->lab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );
PLFLT x[6], y[6];
for ( int i = 0; i < 6; i++ )
{
x[i] = .2 * i;
y[i] = x[i] * x[i];
}
pls->col( Red );
pls->poin( 6, x, y, 2 );//绘制点,最后一个参数表示点的类型
pls->col( DeepBlue );
pls->width(2);//设置线宽
pls->lsty(2);//设置线性,1-8可选
//pls->mtex("b",0,0,0,"y=x");
pls->line( 6, x, y );
}
2010工程文件地址:plot_sample2