根據官方實例修改,主要實現如上效果,QCustomPlot 繪圖的座標軸正常有四個 :橫軸下邊(xAxis)默認顯示,橫軸上邊(xAxis2),縱軸左邊(yAxis)默認顯示,縱軸右邊邊(yAxis2)。
demoName = "Quadratic Demo";
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
x[i] = i/50.0 - 1; // x goes from -1 to 1
y[i] = x[i]*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph(); /*創建一個圖表*/
customPlot->graph(0)->setData(x, y); /*設置數據*/
// give the axes some labels:
customPlot->xAxis2->setLabel("x2");
customPlot->xAxis->setVisible(false);
customPlot->yAxis->setLabel("y"); /*設置座標軸的名字*/
// set axes ranges, so we see all data:
customPlot->xAxis2->setRange(-1, 1);
customPlot->xAxis2->setVisible(true); /*設置是否顯示*/
customPlot->yAxis->setRange(0, 1); /*設置座標軸的範圍*/
customPlot->yAxis->setRangeReversed(true);/*刻度範圍是否翻轉,即刻度0變爲最大值,最大值變爲最小值*/