QCustomPlot之盒須圖(十六)

盒須圖的組成如下圖所示:

盒須圖

在QCustomPlot中創(chuàng)建一個盒須圖所需的類:QCPStatisticalBox,為盒須圖添加數(shù)據(jù)主要使用的是addData接口,接口定義如下:
void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector<double> &outliers=QVector<double>());

參數(shù) 含義
key 在key軸的位置
minimum 下邊緣
lowerQuartile 下四分位數(shù)
median 中位數(shù),同時也是在value軸的位置
upperQuartile 上四分位數(shù)
maximum 上邊緣
outliers 異常值

盒須圖風格

函數(shù) 含義
setWidth 設(shè)置盒子寬度,寬度大小是按key軸的坐標確定的
setWhiskerWidth 設(shè)置邊緣線寬度,寬度大小是按key軸的坐標確定的
setWhiskerPen 設(shè)置邊緣線到四分數(shù)的線段的畫筆風格
setWhiskerBarPen 設(shè)置邊緣線畫筆風格
setWhiskerAntialiased 盒須(下邊緣到四分位數(shù)的線以及下邊緣線)是否是反鋸齒
setMedianPen 中位數(shù)畫筆風格
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);

    // 設(shè)置軸風格
    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);
}
效果圖
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容