界面:

核心代码:

  customPlot->legend->setVisible(true);customPlot->legend->setFont(QFont("Helvetica",9));// set locale to english, so we get english decimal separator:customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));// add confidence band graphs:customPlot->addGraph();QPen pen;pen.setStyle(Qt::DotLine);pen.setWidth(1);pen.setColor(QColor(180,180,180));customPlot->graph(0)->setName("Confidence Band 68%");customPlot->graph(0)->setPen(pen);customPlot->graph(0)->setBrush(QBrush(QColor(255,50,30,20)));customPlot->addGraph();customPlot->legend->removeItem(customPlot->legend->itemCount()-1); // don't show two confidence band graphs in legendcustomPlot->graph(1)->setPen(pen);customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));// add theory curve graph:customPlot->addGraph();pen.setStyle(Qt::DashLine);pen.setWidth(2);pen.setColor(Qt::red);customPlot->graph(2)->setPen(pen);customPlot->graph(2)->setName("Theory Curve");// add data point graph:customPlot->addGraph();customPlot->graph(3)->setPen(QPen(Qt::blue));customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);customPlot->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4));customPlot->graph(3)->setErrorType(QCPGraph::etValue);customPlot->graph(3)->setErrorPen(QPen(QColor(180,180,180)));customPlot->graph(3)->setName("Measurement");// generate ideal sinc curve data and some randomly perturbed data for scatter plot:QVector<double> x0(250), y0(250);QVector<double> yConfUpper(250), yConfLower(250);for (int i=0; i<250; ++i){x0[i] = (i/249.0-0.5)*30+0.01; // by adding a small offset we make sure not do divide by zero in next code liney0[i] = sin(x0[i])/x0[i]; // sinc functionyConfUpper[i] = y0[i]+0.15;yConfLower[i] = y0[i]-0.15;x0[i] *= 1000;}QVector<double> x1(50), y1(50), y1err(50);for (int i=0; i<50; ++i){// generate a gaussian distributed random number:double tmp1 = rand()/(double)RAND_MAX;double tmp2 = rand()/(double)RAND_MAX;double r = sqrt(-2*log(tmp1))*cos(2*M_PI*tmp2); // box-muller transform for gaussian distribution// set y1 to value of y0 plus a random gaussian pertubation:x1[i] = (i/50.0-0.5)*30+0.25;y1[i] = sin(x1[i])/x1[i]+r*0.15;x1[i] *= 1000;y1err[i] = 0.15;}// pass data to graphs and let QCustomPlot determine the axes ranges so the whole thing is visible:customPlot->graph(0)->setData(x0, yConfUpper);customPlot->graph(1)->setData(x0, yConfLower);customPlot->graph(2)->setData(x0, y0);customPlot->graph(3)->setDataValueError(x1, y1, y1err);customPlot->graph(2)->rescaleAxes();customPlot->graph(3)->rescaleAxes(true);// setup look of bottom tick labels:customPlot->xAxis->setTickLabelRotation(30);customPlot->xAxis->setAutoTickCount(9);customPlot->xAxis->setNumberFormat("ebc");customPlot->xAxis->setNumberPrecision(1);customPlot->xAxis->moveRange(-10);// make top right axes clones of bottom left axes. Looks prettier:customPlot->axisRect()->setupFullAxesBox();

源码:

https://gitee.com/zhangtongxueruanjiankaifa/qcustom-plot-demo/tree/master/SincScatterDemo

QCustomPlot 1.0.1学习(5)-Sinc函数绘制相关推荐

  1. QCustomPlot 1.0.1学习(1)-下载和使用QCustomPlot

    1.QCustomPlot介绍 QCustomPlot is a Qt C++ widget for plotting and data visualization. It has no furthe ...

  2. R语言学习心得-plot函数绘制双Y轴图像

    由于个人在学习过程中遇到绘制双Y轴图像问题,在初步搜索未发现相关完整教程,故写下本文以此抛砖引玉.文中的方法个人认为尚可优化,仅供参考.如有任何疑问欢迎在评论区共同讨论学习. 待处理的数据为" ...

  3. Sinc函数同一个定积分, 三种不同的方法

    01 Sinc函数 一.背景介绍   有一个函数,名字叫Sinc函数,也被称为抽样函数,  Sinc函数定义为sin(x) 除以x.  函数图像是一个左右对称的偶函数,呈现漂亮的震荡衰减的趋势.  S ...

  4. mysql存储过程大于小于_mysql5.0存储过程操作符知识_函数方法[Mysql学习]

    mysql存储过程基本函数 一.字符串类 CHARSET(str) //返回字串字符集 CONCAT (string2  [,... ]) //连接字串 INSTR (string ,substrin ...

  5. (原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(5): 返回指定表格中的所有键(key):table.keys...

    这里的函数主要用来做:返回指定表格中所有的键.参考资料为quick_cocos. 星月倾心贡献~~~ --[[ -- 返回指定表格中的所有键(key) -- example:local t = ( a ...

  6. (原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(8): 生成只读table

    这个函数的作用是:生成只读table. --[[ -- 生成只读table -- @param table t 需要不允许修改的tableexample:local tb = {"星期一&q ...

  7. 方波与sinc函数之间的最全傅里叶变换关系_助记_有图有推导

    方波与sinc函数的最全傅里叶变换对_助记_有图有推导 文章目录 方波与sinc函数的最全傅里叶变换对\_助记\_有图有推导 1.连续时间周期信号傅里叶变化下的方波与sinc 2.离散时间周期信号傅里 ...

  8. 《ANSYS 14.0超级学习手册》一第2章 高级应用的基石——APDL

    本节书摘来自异步社区<ANSYS 14.0超级学习手册>一书中的第2章,作者 张建伟 , 白海波 , 李昕, 更多章节内容可以访问云栖社区"异步社区"公众号查看 第2章 ...

  9. 0基础学习数据分析必须掌握的技能有哪些?

    现如今,我们处于一个互联网发展的时代,大大小小的企业对于数据分析相关岗位的需求逐渐增加,因为所有的企业都有数据,企业需要让数据分析师通过整理.分析企业数据总结出企业目前的发展现状,并且为企业做出下一步 ...

最新文章

  1. Struts2学习笔记-part1: 快速起步
  2. 在单链表和双链表中删除倒数第K个节点
  3. Angular特殊的选择器:host,:host-context,::ng-deep
  4. zabbix-server-mysql安装_zabbix server 安装部署
  5. kafka偏移量保存到mysql里_Kafka 新版消费者 API(二):提交偏移量
  6. 2019蓝桥杯省赛---java---B---7(外卖店优先级)
  7. 常见 Java 字节码 指令 助记符
  8. 如何查看node的版本及安装的位置?
  9. java list详解_Java 中 list 用法案例详解
  10. 排序 八种经典排序算法
  11. 网站服务器怎么用手机登录不了怎么办,怎么打不开服务器列表了?
  12. es6 Generator函数概述
  13. 2017.10.10 杀人游戏 思考记录
  14. MyBatis插入数据返回插入对象的主键
  15. 《TensorFlow 2.0深度学习算法实战教材》学习笔记(七、Kears高层接口)
  16. Android数据的几种存储方式---------SharePreferences(轻量的以键值对) 的使用
  17. 关于浏览器兼容的问题
  18. python语言程序设计实践教程陈东_《Python语言程序设计实践教程》陈东著【摘要 书评 在线阅读】-苏宁易购图书...
  19. 中文文本标注工具调研以及BRAT安装使用
  20. 常用编程语言介绍及特点

热门文章

  1. 特种浓缩分离:倒极电渗析技术工作原理介绍
  2. 一种更优雅的蓝牙配对技术 - Cross-transport key derivation (CTKD)
  3. 一文带你读懂点击劫持详解+实验
  4. 葫芦书笔记----CNN和RNN
  5. 一周AI资讯|深度学习如何进行“读心术”?
  6. Linux下Oracle 11G r2 (64位)安装
  7. TSP问题(贪心法)最近邻点和最短连接
  8. 《黑客与画家》摘要读后感
  9. Control Egress Traffic
  10. salt内置执行模块列表