簡體   English   中英

如何使用QCustomPlot QT5繪制多個點?

[英]How to plot multiple points using QCustomPlot QT5?

以下是一些示例點:

(1,1),(2,3),(3,1),(4,2),(1,5),(3,4)

我想依次用線繪制這些點,將它們添加到向量xy 然后,執行setData(x,y)
但是, QCustomPlot似乎只能按x軸的順序繪制點。 我注意到這些點是由setData(x,y)自動排序的。

如何按原始順序繪制這些點?

您正在尋找的是使用QCPCurve而不是Graph。

限定:

QCPCurve *newCurve;

並通過執行以下操作來啟動它:

this->newCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
ui->customPlot->addPlottable(this->newCurve);

然后,可以像使用Graph一樣使用它:

QVector<double> x, y;
//...
this->newCurve->setData(x, y);

另請參見以下示例: 參數曲線演示

基於A. Sarid的幫助,我在演示中找到了QCPCurve的用法(11)。 QCPCurve和QCPGraph之間的區別在於,一個Q可以與QCPCurve的不同y相對應。 因此,只需添加代碼:

QCPCurve * newCurve =新的QCPCurve(ui-> customPlot-> xAxis,ui-> customPlot-> yAxis); newCurve->使用setData(X,Y);

再次感謝A. Sarid!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM