Hi, I just started programming in qt and qcp. And was wondering if its possible to add multiple color maps in a single plot. In my program I have a push button which should add the second color but instead I am getting the following error:

bool QCPLayoutGrid::addElement(int, int, QCPLayoutElement*) There is already an element in the specified row/column: 0 1

Here is my 2 functions which adds color maps:

void MainWindow::setupPlottingArea(QCustomPlot *customPlot) {
    // configure axis rect:
    customPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); // this will also allow rescaling the color scale by dragging/zooming
    customPlot->axisRect()->setupFullAxesBox(true);
    customPlot->xAxis->setLabel("x");
    customPlot->yAxis->setLabel("y");

    // set up the QCPColorMap:
    QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis, customPlot->yAxis);
    int nx = 500;
    int ny = nx * 0.555;
    colorMap->data()->setSize(nx, ny); // we want the color map to have nx * ny data points
    colorMap->data()->setRange(QCPRange(0, 8), QCPRange(0, 20)); // and span the coordinate range -4..4 in both key (x) and value (y) dimensions
    colorMap->setInterpolate(false);//to get visible pixel pattern
    // now we assign some data, by accessing the QCPColorMapData instance of the color map:
       // double lastX = 0, lastY = 0;
        for (int i = 1; i <= 100; i++)
    {
        for(int j=1; j<= 100; j++)
        {
         int xIndex, yIndex;
            double xCoord, yCoord;
            xCoord = (j* 0.02);
            yCoord = (j* 0.04) + (0.062 * i);
            colorMap->data()->coordToCell(xCoord,yCoord, &xIndex, &yIndex);
            colorMap->rescaleDataRange(true);
            colorMap->data()->setCell(xIndex, yIndex, 200);
            lastX = xCoord;
            lastY = yCoord;
        }
     } //end for loop

    // add a color scale:
    QCPColorScale *colorScale = new QCPColorScale(customPlot);
    customPlot->plotLayout()->addElement(0, 1, colorScale); // add it to the right of the main axis rect
    colorScale->setType(QCPAxis::atRight); // scale shall be vertical bar with tick/axis labels right (actually atRight is already the default)
    colorMap->setColorScale(colorScale); // associate the color map with the color scale
    colorScale->axis()->setLabel("Magnetic Field Strength");

    // set the color gradient of the color map to one of the presets:
    colorMap->setGradient(QCPColorGradient::gpPolar);
    // we could have also created a QCPColorGradient instance and added own colors to
    // the gradient, see the documentation of QCPColorGradient for what's possible.

    // rescale the data dimension (color) such that all data points lie in the span visualized by the color gradient:
    colorMap->rescaleDataRange();

    // make sure the axis rect and color scale synchronize their bottom and top margins (so they line up):
    QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot);
    customPlot->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
    colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);

    // rescale the key (x) and value (y) axes so the whole color map is visible:
    customPlot->rescaleAxes();
}


void MainWindow::on_range5_btn_clicked()
{
    qInfo("I am working");
    // set up the QCPColorMap:
    QCPColorMap *colorMap2 = new QCPColorMap(ui->customPlot->xAxis, ui->customPlot->yAxis);
    int nx = 500;
    int ny = nx * 0.555;
    colorMap2->data()->setSize(nx, ny); // we want the color map to have nx * ny data points
    colorMap2->data()->setRange(QCPRange(0, 8), QCPRange(20, 30)); // and span the coordinate range -4..4 in both key (x) and value (y) dimensions
    colorMap2->setInterpolate(false);//to get visible pixel pattern
    // now we assign some data, by accessing the QCPColorMapData instance of the color map for range 10:

        for (int i = 1; i <= 1; i++)
    {
        for(int j=1; j<= 2; j++)
        {
         int xIndex, yIndex;
            double xCoord, yCoord;
            xCoord = (j* 0.043);
            yCoord = 20 + (j* 0.08) + (0.123 * i);
            colorMap2->data()->coordToCell(xCoord,yCoord, &xIndex, &yIndex);
            colorMap2->rescaleDataRange(true);
            colorMap2->data()->setCell(xIndex, yIndex, 200);
        }
     } //end for loop


    // add a color scale:
    QCPColorScale *colorScale = new QCPColorScale(ui->customPlot);
    ui->customPlot->plotLayout()->addElement(0, 1, colorScale); // add it to the right of the main axis rect
    colorScale->setType(QCPAxis::atRight); // scale shall be vertical bar with tick/axis labels right (actually atRight is already the default)
    colorMap2->setColorScale(colorScale); // associate the color map with the color scale
    colorScale->axis()->setLabel("Magnetic Field Strength");

    // set the color gradient of the color map to one of the presets:
    colorMap2->setGradient(QCPColorGradient::gpPolar);
    // we could have also created a QCPColorGradient instance and added own colors to
    // the gradient, see the documentation of QCPColorGradient for what's possible.

    // rescale the data dimension (color) such that all data points lie in the span visualized by the color gradient:
    colorMap2->rescaleDataRange();

    // make sure the axis rect and color scale synchronize their bottom and top margins (so they line up):
    QCPMarginGroup *marginGroup = new QCPMarginGroup(ui->customPlot);
    ui->customPlot->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);
    colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup);

    // rescale the key (x) and value (y) axes so the whole color map is visible:
    ui->customPlot->rescaleAxes();

}