QCustomPlot: Plotting 2 Colormaps - Axes and Ticks Dissappear

644 Views Asked by At

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));

The result looks like this:

Example of 2 Color Plots

So, clearly, the lower plot misses ticks and axes.

1

There are 1 best solutions below

0
Stefanowitschko On

In case any one else will be wondering about this: The question was answered somewhere else,

https://www.qcustomplot.com/index.php/support/forum/2269

The trick was to put all axes on the "axes" layer with

      axis->setLayer("axes");