You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在QCustomPlot中实现两条曲线间区域着色?求替代方案

QCustomPlot中填充两条曲线之间区域的最优实现方法?

已知可通过customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20)));实现曲线与X轴间的区域填充,但我的需求是填充两条曲线之间的区域,而非曲线与X轴之间。

目前采用临时方案:绘制宽度等于彩色区域的线条,代码如下:

QVector<double> x{1e8, 5e9, 1e10, 1.5e10};
QVector<double> y{-40, -40, -35, -32};
QVector<double> y2{-39.5, -39.5, -34.5, -31.5};

ui->widget->addGraph();
ui->widget->graph(0)->setData(x, y);

ui->widget->addGraph();
ui->widget->graph(1)->setData(x, y2);
QPen blueDotPen;
blueDotPen.setColor(QColor(0, 0, 255, 20));
blueDotPen.setWidth(25);
ui->widget->graph(1)->setPen(blueDotPen);
ui->widget->graph(1)->setLineStyle(QCPGraph::lsLine);

ui->widget->xAxis->setLabel("x");
ui->widget->yAxis->setLabel("y");

ui->widget->xAxis->setRange(1e8, 1.5e10);
ui->widget->yAxis->setRange(-30, -50);
ui->widget->replot();

请问是否有更优的实现方式,比如类似曲线与X轴填充的方法?

内容的提问来源于stack exchange,提问作者temp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:05:19