My code (based on https://www.programmersought.com/article/41487208488/ blog) is as follows. I want to accomplish a simple job of shifting one of the axis to right side of the rectangle and not 2 axes on the left. I have tried various things but was not able to do it. Any help would be appreciated.
QCPAxisRect *wideAxisRect; QCPGraph *mainGraphGauss; QCPGraph *mainGraphGauss2; QCPGraph *mainGraphCos; void MainWindow::setupAdvancedAxesDemo2(QCustomPlot *customPlot) { demoName = "Advanced Axes Demo"; customPlot->plotLayout()->clear(); wideAxisRect = new QCPAxisRect(customPlot, true); wideAxisRect->setupFullAxesBox(true); wideAxisRect->addAxis(QCPAxis::atLeft)->setTickLabelColor(QColor("#6050F8")); QCPLayoutGrid *subLayout = new QCPLayoutGrid; customPlot->plotLayout()->addElement(0, 0, wideAxisRect); // add axis rectangle in the first line // Keep a good habit and place them on the corresponding layer foreach (auto *rect, customPlot->axisRects()) { foreach (auto *axis, rect->axes()) { axis->setLayer("axes"); axis->grid()->setLayer("grid"); } } // prepare data QVector<QCPGraphData> dataCos(21), dataGauss(50), dataRandom(100); QVector<double> x3, y3; qsrand(3); for (int i=0; i<dataCos.size(); ++i) { dataCos[i].key = i/(double)(dataCos.size()-1)*10-5.0; dataCos[i].value = qCos(dataCos[i].key); } for (int i=0; i<dataGauss.size(); ++i) { dataGauss[i].key = i/(double)dataGauss.size()*10-5.0; dataGauss[i].value = qExp(-dataGauss[i].key*dataGauss[i].key*0.2)*1000; } for (int i=0; i<dataRandom.size(); ++i) { dataRandom[i].key = i/(double)dataRandom.size()*10; dataRandom[i].value = qrand()/(double)RAND_MAX-0.5+dataRandom[qMax(0, i-1)].value; } x3 << 1 << 2 << 3 << 4; y3 << 2 << 2.5 << 4 << 1.5; QCPAxis *x_bottom = new QCPAxis(wideAxisRect, QCPAxis::atBottom); QCPAxis *y1_left = new QCPAxis(wideAxisRect, QCPAxis::atLeft); mainGraphCos = customPlot->addGraph(wideAxisRect->axis(QCPAxis::atBottom), wideAxisRect->axis(QCPAxis::atLeft)); mainGraphCos->data()->set(dataCos); mainGraphCos->valueAxis()->setRange(-1, 1); mainGraphCos->rescaleKeyAxis(); mainGraphCos->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black), QBrush(Qt::white), 6)); mainGraphCos->setPen(QPen(QColor(120, 120, 120), 2)); mainGraphGauss = customPlot->addGraph(wideAxisRect->axis(QCPAxis::atBottom), wideAxisRect->axis(QCPAxis::atLeft, 1)); mainGraphGauss->data()->set(dataGauss); mainGraphGauss->setPen(QPen(QColor("#8070B8"), 2)); mainGraphGauss->setBrush(QColor(110, 170, 110, 30)); mainGraphCos->setChannelFillGraph(mainGraphGauss); mainGraphCos->setBrush(QColor(255, 161, 0, 50)); mainGraphGauss->valueAxis()->setRange(0, 1000); mainGraphGauss->rescaleKeyAxis(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); customPlot->setSelectionRectMode(QCP::SelectionRectMode::srmZoom); }