qwtplot绘图

需要插入的头文件

这些头文件都通过编译qwtplot6.1.3产生,编译见VS2015配置64位qwt6.1.3

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_canvas.h>
#include <qdatetime.h>
#include <qwt_abstract_scale_draw.h>
#include <qwt_plot_grid.h>
#include <qwt_scale_widget.h>
#include <qwt_plot_layout.h>
#include <qwt_symbol.h> 

初始变量定义

QVector<double> m_DataVectorX;
QVector<double> m_DataVectorY;
QwtPlot *m_ProfileQwtPlot;
QwtPlotCurve *m_ProfileCurve;
void ShowCurve();

函数实现

void Resonator::ShowCurve()
{

	m_ProfileQwtPlot = new QwtPlot(this);
	m_ProfileQwtPlot->move(20, 50);
	m_ProfileQwtPlot->setFixedWidth(300);    // 设置坐标轴的大小
	m_ProfileQwtPlot->setFixedHeight(300);
	m_ProfileQwtPlot->setTitle("Curve");         // 设置坐标轴的标题
	m_ProfileQwtPlot->setAxisScale(QwtPlot::yLeft, -4, 4, 1); // 坐标轴的范围和间隔
	m_ProfileQwtPlot->setAxisScale(QwtPlot::xBottom, -4, 4, 1);
	m_ProfileQwtPlot->enableAxis(QwtPlot::xBottom, true);
	m_ProfileQwtPlot->setStyleSheet("background:transparent;");//删除坐标轴背景
	m_ProfileQwtPlot->setAxisMaxMinor(QwtPlot::xBottom, 5);
	m_ProfileQwtPlot->setAxisMaxMinor(QwtPlot::yLeft, 5);//设置每一个大格有都少个小格
	m_ProfileQwtPlot->setCanvasBackground(Qt::white); // 设置背景白色

	for (int n = 0; n < m_ProfileQwtPlot->axisCnt; n++)
	{
		QwtScaleWidget *poScaleWidget = m_ProfileQwtPlot->axisWidget(n);
		if (poScaleWidget)
		{
			poScaleWidget->setMargin(0);
		}
		QwtScaleDraw *poScaleDraw = m_ProfileQwtPlot->axisScaleDraw(n);
		if (poScaleDraw)
		{
			poScaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
		}
	}
	m_ProfileQwtPlot->plotLayout()->setAlignCanvasToScales(true);

	QwtPlotGrid *grid = new QwtPlotGrid();
	grid->enableXMin(true);
	grid->enableYMin(true);
	grid->enableX(true);
	grid->enableY(true);
	grid->setMajorPen(QPen(Qt::gray, 0, Qt::SolidLine));  // 大网格
	grid->setMinorPen(QPen(QColor(186, 186, 186), 0, Qt::DotLine));// 小网格
	grid->attach(m_ProfileQwtPlot);

	m_ProfileCurve = new QwtPlotCurve;
	m_ProfileCurve->setPen(QColor(255, 85, 255), 2, Qt::SolidLine);
	m_ProfileCurve->setCurveAttribute(QwtPlotCurve::Fitted, true);   
	m_ProfileCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
	QwtSymbol *symbol = new QwtSymbol(QwtSymbol::NoSymbol,
		QBrush(Qt::white), QPen(Qt::red, 2), QSize(3, 3));//设置样本点的颜色、大小 
	m_ProfileCurve->setSymbol(symbol);
	m_ProfileCurve->attach(m_ProfileQwtPlot);  


	//读数据画图
	QFile fr("data/circle_noise.txt");
	if (!fr.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		qDebug() << "LLLLLLL" << endl;
		return;
	}
	QTextStream in(&fr);
	QStringList numList;
	while (!in.atEnd())
	{
		numList = in.readLine().split(" ");
		m_DataVectorX.push_back(numList[0].toDouble());
		m_DataVectorY.push_back(numList[1].toDouble());
	}
	m_ProfileCurve->setSamples(m_DataVectorX, m_DataVectorY);
	m_ProfileCurve->setPen(QPen(Qt::blue));
	m_ProfileQwtPlot->replot();
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值