QCustomPlot的简单使用

本文介绍如何使用QCustomPlot库进行简单的图标绘制。通过一个示例程序展示了如何创建一个QCustomPlot widget,并绘制y=x^2的曲线图。文中还提供了设置坐标轴范围和标签的方法。

简单的图标绘制可以用QCustomPlot 就一个cpp和一个.h文件包含

其他的还有QT自身的QChart,不过要QT5.X以后的版本



下载QCustomPlot  http://qcustomplot.com/index.php


最主要的类是 QCustomPlot,这是一个widget。所有的画图都是基于这个widget.


按照文章中基础的来写一个。

       QCustomPlot customPlot() ;
customPlot.resize(600,400);
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=50; i<80; ++i)
{
x[i] = i/50.0 - 1; // x goes from -1 to 1
y[i] = x[i]*x[i]; // let's plot a quadratic function
}

// create graph and assign data to it:
customPlot.addGraph();
customPlot.graph(0)->setData(x, y);
// give the axes some labels:
customPlot.xAxis->setLabel("x");
customPlot.yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot.xAxis->setRange(-1, 1);
customPlot.yAxis->setRange(0, 1);
customPlot.replot();
customPlot.show();

实现了y=x^2的画图

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值