技术专栏
Qt之qcustomplot绘图总结
首先我用customplot的时候需要先知道它内部类的使用方式和作用,比如以下的图像部分:
QCPGraph :折线图
QCPCurve:用于曲线图,可以有循环
QCPBars:柱形图,如果有多个QCPBars ,可以依次重叠
QCPStatisticalBox(需实例化):盒子图
QCPColorMap(实例化):色谱图
QCPFinancial(实例化):金融图
QCPAbstractItem:标示项
包括:
QCPItemStraightLine:直线
QCPItemLine:线段
QCPItemCurve:曲线
QCPItemRect:矩形
QCPItemEllipse:椭圆
QCPItemText:文本
QCPItemTracer:小圆球
QCPItemPixmap:图片
QCPItemBracket:括弧
布局项(QCPLayoutElement):布局项(QCPAbstractLegendItem)、坐标轴矩形(QCPAxisRect)
网格线(QCPGrid):每一个坐标轴对应一个网格线
坐标轴(QCPAxis):一个坐标轴矩形包含四个坐标轴,上下左右四个坐标轴。
简易demo:
void MainWindow::setupSimpleDemo(QCustomPlot *customPlot)
{
demoName = "Simple Demo";
// add two new graphs and set their look:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
// generate some points of data (y0 for first, y1 for second graph):
QVector<double> x(250), y0(250), y1(250);
for (int i=0; i<250; ++i)
{
x[i] = i;
y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
y1[i] = qExp(-i/150.0); // exponential envelope
}
customPlot->xAxis->setRange(0, 250);
customPlot->xAxis->setAutoTickStep(false);
customPlot->xAxis->setTickStep(25);
customPlot->xAxis->setAutoSubTicks(false);
customPlot->xAxis->setSubTickCount(9);
customPlot->yAxis->setRange(0, 10);
// configure right and top axis to show ticks but no labels:
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
customPlot->xAxis2->setVisible(true);
customPlot->xAxis2->setTickLabels(false);
customPlot->yAxis2->setVisible(true);
customPlot->yAxis2->setTickLabels(false);
// make left and bottom axes always transfer their ranges to right and top axes:
connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
// pass data points to graphs:
customPlot->graph(0)->setData(x, y0);
customPlot->graph(1)->setData(x, y1);
// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
customPlot->graph(0)->rescaleAxes();
// same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
customPlot->graph(1)->rescaleAxes(true);
// Note: we could have also just called customPlot->rescaleAxes(); instead
// Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
点赞
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包
暂无数据
相关专栏
-
浏览量:3386次2020-05-07 19:43:16
-
浏览量:7339次2020-08-23 21:25:35
-
浏览量:2830次2020-08-23 20:59:44
-
浏览量:6786次2021-01-16 15:50:24
-
浏览量:6338次2020-08-22 16:31:22
-
浏览量:5172次2017-11-16 11:35:44
-
浏览量:5557次2020-08-23 21:17:12
-
浏览量:5316次2020-08-23 21:07:51
-
浏览量:2859次2020-08-21 19:39:43
-
浏览量:4750次2020-09-23 22:47:30
-
浏览量:6635次2018-01-22 14:23:15
-
浏览量:2918次2020-05-06 15:52:54
-
浏览量:3035次2017-11-28 12:33:29
-
浏览量:9082次2020-05-07 14:42:07
-
浏览量:3702次2020-08-18 19:54:58
-
浏览量:10287次2020-12-07 23:36:10
-
浏览量:1683次2019-12-31 16:25:11
-
浏览量:9306次2020-11-17 15:41:28
-
浏览量:5774次2020-09-23 23:07:37
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者
big_anana
您的支持将鼓励我继续创作!
打赏金额:
¥1
¥5
¥10
¥50
¥100
支付方式:
微信支付
打赏成功!
感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注