qt-绘制曲线(qcustomplot)

该代码段展示了如何使用QCustomPlot库在GUI中添加并配置数据曲线,包括设置交互式功能如拖动和缩放,设定坐标轴标签,自动调整轴的范围以显示所有数据,以及显示图例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       #include "qcustomplot.h"
         ui.customplot->addGraph();//添加数据曲线(一个图像可以有多个数据曲线)
    ui.customplot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom|QCP::iSelectPlottables);//
    // graph(0);可以获取某个数据曲线(按添加先后排序)
    // setData();为数据曲线关联数据
    ui.customplot->graph(0)->setData(point_x, point_y);
    ui.customplot->graph(0)->setName("曲线图");// 设置图例名称
    // 为坐标轴添加标签
    ui.customplot->xAxis->setLabel("x");
    ui.customplot->yAxis->setLabel("y");
    // 设置坐标轴的范围,以看到所有数据
    auto max_x = std::max_element(std::begin(point_x), std::end(point_x));
    auto min_x = std::min_element(std::begin(point_x), std::end(point_x));
    auto max_y = std::max_element(std::begin(point_y), std::end(point_y));
    auto min_y = std::min_element(std::begin(point_y), std::end(point_y));
    double Max_x = *max_x;
    double Min_x = *min_x;
    double Max_y = *max_y;
    double Min_y = *min_y;
    ui.customplot->xAxis->setRange(double(Min_x), double(Max_x));
    ui.customplot->yAxis->setRange(double(Min_y), double(Max_y));
    ui.customplot->legend->setVisible(true); // 显示图例
    // 重画图像
    ui.customplot->replot();

使用了qcustomplot库,需要单独下载,网上很多,如果找不到,字数限制我贴不上,找不到的私聊我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值