QCustomPlot之盒须图(十六)

盒须图的组成如下图所示:

盒须图

在QCustomPlot中创建一个盒须图所需的类:QCPStatisticalBox,为盒须图添加数据主要使用的是addData接口,接口定义如下:
void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector<double> &outliers=QVector<double>());

参数含义
key在key轴的位置
minimum下边缘
lowerQuartile下四分位数
median中位数,同时也是在value轴的位置
upperQuartile上四分位数
maximum上边缘
outliers异常值
盒须图风格
函数含义
setWidth设置盒子宽度,宽度大小是按key轴的坐标确定的
setWhiskerWidth设置边缘线宽度,宽度大小是按key轴的坐标确定的
setWhiskerPen设置边缘线到四分数的线段的画笔风格
setWhiskerBarPen设置边缘线画笔风格
setWhiskerAntialiased盒须(下边缘到四分位数的线以及下边缘线)是否是反锯齿
setMedianPen中位数画笔风格
setOutlierStyle异常值风格
盒须图的使用
void MainWindow::setupStatisticalDemo(QCustomPlot *customPlot)
{
    QCPStatisticalBox *statistical = new QCPStatisticalBox(customPlot->xAxis, customPlot->yAxis);
    QBrush boxBrush(QColor(60, 60, 255, 100));
    boxBrush.setStyle(Qt::Dense6Pattern); // 使它看起来很老派
    statistical->setBrush(boxBrush);

    statistical->addData(1, 1.1, 1.9, 2.25, 2.7, 4.2);
    statistical->addData(2, 0.8, 1.6, 2.2, 3.2, 4.9, QVector<double>() << 0.7 << 0.34 << 0.45 << 6.2 << 5.84); // 添加一些异常值
    statistical->addData(3, 0.2, 0.7, 1.1, 1.6, 2.9);

    // 设置轴风格
    customPlot->xAxis->setSubTicks(false);
    customPlot->xAxis->setTickLength(0, 4);
    customPlot->xAxis->setTickLabelRotation(20);
    QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
    textTicker->addTick(1, "Sample 1");
    textTicker->addTick(2, "Sample 2");
    textTicker->addTick(3, "Control Group");
    customPlot->xAxis->setTicker(textTicker);

    customPlot->yAxis->setLabel("O₂ Absorption [mg]");
    customPlot->rescaleAxes();
    customPlot->xAxis->scaleRange(1.7, customPlot->xAxis->range().center());
    customPlot->yAxis->setRange(0, 7);
    customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
}

效果图

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值