当前位置: 首页 > news >正文

qt实现功率谱和瀑布图

瀑布图


配置qcustomplot的例子网上有很多了,记录下通过qcustomplot实现的功率谱和瀑布图代码:

void WaveDisplay::plotWaterfall(MCustomPlot* p_imag)
{
    mCustomPlotLs = p_imag;

    mCustomPlotLs->plotLayout()->clear(); // clear default axis rect so we can start from scratch
    mCustomPlotLs->showTracer(true);
    QCPLayoutGrid *subLayoutF = new QCPLayoutGrid;
    QCPLayoutGrid *subLayoutL = new QCPLayoutGrid;

    mCustomPlotLs->setInteractions(QCP::iRangeDrag       //可平移
                                | QCP::iRangeZoom        //可滚轮缩放
                                | QCP::iSelectPlottables //可选中曲线
                                | QCP::iSelectLegend );  //可选中图例
    wideAxisRectF = new QCPAxisRect(mCustomPlotLs);
    wideAxisRectL = new QCPAxisRect(mCustomPlotLs);
    mCustomPlotLs->plotLayout()->addElement(1, 0, subLayoutF);    // insert axis rect in first row
    mCustomPlotLs->plotLayout()->addElement(0, 0, subLayoutL);    // sub layout in second row (grid layout will grow accordingly)

    QCPMarginGroup *marginGroup = new QCPMarginGroup(mCustomPlotLs);
    wideAxisRectF->setMarginGroup(QCP::msBottom, marginGroup);
    wideAxisRectL->setMarginGroup(QCP::msBottom, marginGroup);

    subLayoutF->addElement(0, 0, wideAxisRectF);
    wideAxisRectF->setupFullAxesBox(true);
    wideAxisRectF->axis(QCPAxis::atLeft)->setRange(-130, 0); // 设置轴上限和下限
    wideAxisRectF->axis(QCPAxis::atBottom)->setRange(0, 50);
    wideAxisRectF->axis(QCPAxis::atBottom)->ticker()->setTickCount(10);//10个主刻度
    wideAxisRectF->axis(QCPAxis::atBottom)->setLabel("频率(KHz)");
    wideAxisRectF->axis(QCPAxis::atLeft)->setLabel("dB");
    wideAxisRectF->axis(QCPAxis::atLeft)->setPadding(20);
    wideAxisRectF->axis(QCPAxis::atRight)->setTickLabels(true);
    wideAxisRectF->axis(QCPAxis::atRight)->setPadding(30);


    subLayoutL->addElement(0, 0, wideAxisRectL);
    wideAxisRectL->setupFullAxesBox(true);
    wideAxisRectL->axis(QCPAxis::atLeft)->setRange(0, 100);
    wideAxisRectL->axis(QCPAxis::atLeft)->setSubTicks(false);
    wideAxisRectL->axis(QCPAxis::atLeft)->setTicks(false);
    wideAxisRectL->axis(QCPAxis::atBottom)->setRange(0, 50);
    wideAxisRectL->axis(QCPAxis::atBottom)->ticker()->setTickCount(10);//10个主刻度
    wideAxisRectL->axis(QCPAxis::atBottom)->setLabel("频率(KHz)");
    wideAxisRectL->setRangeZoomFactor(0.8,1); // x轴设置缩放比例,y轴缩放比例为1,则不进行缩放


    // x轴以时间形式显示
    wideAxisRectL->addAxis(QCPAxis::atLeft)->setTickLabelColor(QColor(255,255,255)); // 左边添加一个纵轴
    QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
    timeTicker->setTimeFormat("%h:%m:%s");

    wideAxisRectL->axis(QCPAxis::atLeft, 1)->setTicker(timeTicker);

    connect(wideAxisRectF->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), wideAxisRectL->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange)));
    connect(wideAxisRectL->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), wideAxisRectF->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange)));

    // 功率谱
    mainGraphPower = mCustomPlotLs->addGraph(wideAxisRectF->axis(QCPAxis::atBottom), wideAxisRectF->axis(QCPAxis::atLeft)); // 添加图形
    mainGraphPower->rescaleKeyAxis(); // 自动调整轴范围以展示全部数据
    QPen pen;
    pen.setWidth(1);//线宽
    pen.setStyle(Qt::PenStyle::SolidLine);//虚线  solidline、dashline、dotline、dashdotline、dashdotdotline
    pen.setColor(QColor(255, 253, 85, 255));
    mainGraphPower->setPen(pen);
    mainGraphPower->setSmooth(true);  //  开启平滑曲线


    // 瀑布图
    mainGraphTime = mCustomPlotLs->addGraph(wideAxisRectL->axis(QCPAxis::atBottom), wideAxisRectL->axis(QCPAxis::atLeft, 1));
    mainGraphTime->rescaleKeyAxis();

    colorMapPower = new QCPColorMap(wideAxisRectL->axis(QCPAxis::atBottom), wideAxisRectL->axis(QCPAxis::atLeft));
    int nx = 100;
    int ny = 100;
    colorMapPower->data()->setSize(nx, ny);                            // we want the color map to have nx * ny data points
    colorMapPower->data()->setRange(QCPRange(0, 100), QCPRange(0, 100));

    QCPColorScale *colorScale = new QCPColorScale(mCustomPlotLs); // 添加色条
    subLayoutL->addElement(0, 1, colorScale);
    colorScale->axis()->setTicks(false);
    colorScale->axis()->setTickLabels(false);
    colorScale->setType(QCPAxis::atRight);            // 刻度应为垂直条,刻度线/坐标轴标签右侧(实际上,右侧已经是默认值)
    colorMapPower->setColorScale(colorScale);         // 将颜色图与色标关联
    colorScale->axis()->setLabel("信号强度");
    colorScale->axis()->setLabelColor(Qt::white);
    QCPColorGradient gradient;  // 色条使用的颜色渐变
    gradient.setColorStopAt(0.0, QColor(246,239,166));   // 设置色条开始时的颜色 QColor(246,239,166)
    gradient.setColorStopAt(1.0, QColor(191,68,76));   // 设置色条结束时的颜色

    colorMapPower->setGradient(QCPColorGradient::gpJet); // QCPColorGradient::gpJet QCPColorGradient::gpPolar
    colorMapPower->rescaleDataRange();

    mCustomPlotLs->replot(QCustomPlot::rpQueuedReplot);    // 异步重绘

}
http://www.dtcms.com/a/107683.html

相关文章:

  • Kubernetes APIServer 可观测最佳实践
  • Telnet协议详解:本质与操作逻辑
  • 路由协议分类精讲
  • TrollStore(巨魔商店)介绍及操作手册
  • C 标准库 - `<ctype.h>`
  • Vue el-table-column内el-tooltip识别换行符 \n
  • Mysql的安装
  • java 使用 spring AI 实战MCP
  • centos-LLM+EmbeddingModel+VectorDB-简单模型
  • Aliee,Bengio and Theis:细胞数据上的因果机器学习
  • 代理模式-spring关键设计模式,bean的增强,AOP的实现
  • Spring SpringBoot 细节总结
  • 【ROS】 CMakeLists 文件详解
  • 大数据Spark(五十六):Spark生态模块与运行模式
  • 《 C语言中的变长数组:灵活而强大的特性》
  • 【git项目管理】长话短说
  • JVM生产环境问题定位与解决实战(六):总结篇——问题定位思路与工具选择策略
  • 如何给槽函数传递用户的参数
  • Vue3的组件通信
  • 博卡软件管理中心8:赋能美容美发行业数字化转型的智能解决方案
  • TensorFlow实现逻辑回归
  • 释义ES6中的箭头函数
  • 源码编译安装nginx和php
  • 透过 /proc 看见内核:Linux 虚拟文件系统与 systemd 初始化初探
  • 表面法线估计(Surface Normal Estimation)
  • CSGO 皮肤交易平台后端 (Spring Boot) 代码结构与示例
  • 为什么 js 对象中引用本地图片需要写 require 或 import
  • Windows 实战-evtx 文件分析--笔记
  • 国标GB28181视频监控平台EasyCVR保驾护航休闲娱乐“九小场所”安全运营
  • 基于Python设计的TEQC数据质量可视化分析软件