QCustomPlot Discussion and Comments

Plotting 2 Colormaps - Ticks and Axes disappear...Return to overview

as the title says, I want to plot two colormaps. I want to plot them into the same window but into different axisrects. On top of each other. What happens is that the first color map is plotted nicely, but the second one is overlapping most of the axes and ticks and looks just awful. Here is a minimal working example:

    QCustomPlot * pCstmPlt = new QCustomPlot;
    pCstmPlt->show();
    QCPAxisRect *axisRect = pCstmPlt->axisRect(0);
    axisRect->setupFullAxesBox(true);

    QCPColorMap *colorMap = new QCPColorMap(axisRect->axis(QCPAxis::atBottom),axisRect->axis(QCPAxis::atLeft));
    int Clrny = 100;
    int Clrnx = 100;
    colorMap->data()->setSize(Clrnx, Clrny);
    colorMap->data()->setRange( QCPRange( 1,100 ), QCPRange( 1,100 ) );
    double x, y, dVal;
    for (int xIndex=0; xIndex<100; ++xIndex)
    {
        for (int yIndex=0; yIndex<100; ++yIndex)
        {
            colorMap->data()->cellToCoord(xIndex, yIndex, &x, &y);
            dVal = ( xIndex * yIndex );
            colorMap->data()->setCell(xIndex, yIndex, dVal);
        }
    }
    // add a color scale:
    QCPColorScale *pmycolorScale = new QCPColorScale(pCstmPlt);
    pCstmPlt->plotLayout()->addElement(0, 1, pmycolorScale);
    pmycolorScale->setType(QCPAxis::atRight);
    colorMap->setColorScale(pmycolorScale);
    colorMap->setGradient( QCPColorGradient::gpPolar );

    axisRect = new QCPAxisRect(pCstmPlt,true);
    axisRect->setupFullAxesBox(true);
    pCstmPlt->plotLayout()->addElement(1,0,axisRect);
    QCPColorMap *colorMap2 = new QCPColorMap(axisRect->axis(QCPAxis::atBottom),axisRect->axis(QCPAxis::atLeft));
    colorMap2->data()->setSize(Clrnx, Clrny);
    colorMap2->data()->setRange( QCPRange( 1,100 ), QCPRange( 1,100 ) );
    for (int xIndex=0; xIndex<100; ++xIndex)
    {
        for (int yIndex=0; yIndex<100; ++yIndex)
        {
            colorMap2->data()->cellToCoord(xIndex, yIndex, &x, &y);
            dVal = ( xIndex * yIndex );
            colorMap2->data()->setCell(xIndex, yIndex, dVal);
        }
    }
    // add a color scale:
    QCPColorScale *pmycolorScale2 = new QCPColorScale(pCstmPlt);
    pCstmPlt->plotLayout()->addElement(1, 1, pmycolorScale2);
    pmycolorScale2->setType(QCPAxis::atRight);
    colorMap2->setColorScale(pmycolorScale2);
    colorMap2->setGradient( QCPColorGradient::gpPolar );
    colorMap->rescaleDataRange();
    colorMap2->rescaleDataRange();
    pCstmPlt->rescaleAxes();
    pCstmPlt->setMinimumSize(QSize(500,500));

So the lower plot then misses ticks and axes...

Does anybody know how to solve this???? Thanks!

Seems like you're missing to set up the layers and so everything ends up on the main layer (or what layer you set as current one). Place your new axis rect on the axis layer and your color map on the main layer and everything should be rendered in the proper order. the layout system page has examples at the bottom.

That did the trick! Thank you so much. I was wasting the whole day on this already :)