Plplot绘制简单2D函数图二

  本文在一幅图中显示两张子图,可更换图片背景颜色,绘图颜色,线型和线宽,图例如下:


源程序如下:

#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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值