Qt QCustomPlot简介

引言

官方文档1:官方文档
QCustomPlot 是一个用于绘图和数据可视化的 Qt 库2,使用C++编写。其可以导出为各种格式,应用于数据的实时显示和高质量图像的导出。功能强大,例程如下如所示:
在这里插入图片描述

一、环境配置

我用的Qt 5.14.2:(a) 将源码加入工程 (b).pro里添加 printsupport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport

二、简单使用(验证)

2.1 可视化

在这里插入图片描述在这里插入图片描述

2.2 代码

#include <QtWidgets/QMainWindow>
#include <QApplication>
#include "qcustomplot.h"
#include "math.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // 创建qcustomplot
    QCustomPlot *customPlot =  new QCustomPlot();

    // 画心
    double xx,yy;
    int i = 0;
    QVector<double> x(601), y(601); 
    for(double t=-3; t<=3; t=t+0.01)
    {
        xx = 16*pow(sin(t),3);
        yy = 13*cos(t)-5*cos(t*2)-2*cos(t*3)-cos(t*4);

        //画点
        x[i] = xx;
        y[i] = yy;
        i++;
    }

    // 创建图层 导入数据
    customPlot->addGraph();
    QCPGraph * curGraph = customPlot->graph(0);
    curGraph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCustom, 1));
    customPlot->graph(0)->setData(x, y);
    // 设定坐标轴
    customPlot->xAxis->setVisible(false);
    customPlot->yAxis->setVisible(false);
    // 设定范围
    auto max_x = std::max_element(std::begin(x), std::end(x));
    auto min_x = std::min_element(std::begin(x), std::end(x));
    auto max_y = std::max_element(std::begin(y), std::end(y));
    auto min_y = std::min_element(std::begin(y), std::end(y));
    customPlot->xAxis->setRange(*min_x, *max_x);
    customPlot->yAxis->setRange(*min_y, *max_y);

    // 创建主窗体 并显示
    QMainWindow window;
    window.setCentralWidget(customPlot);
    window.resize(400, 300);
    window.show();

    return a.exec();
}


  1. QCustomPlot Documentation ↩︎

  2. 官方介绍 ↩︎

  3. 下载地址 ↩︎

  4. 配置环境 ↩︎

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大米粥哥哥

感谢认可!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值