QCustomPlot Discussion and Comments

problem with QCPColorMap sizeReturn to overview

i have a problem with colormap sizing.
I set the maximum and minimum x sizes, but when the map is drawn, the right border of the map is larger than the maximum x size that I entered in the code:

qMap->data()->setRange(QCPRange(m_dataMatrix->m_xmin, m_dataMatrix->m_xmax), QCPRange(m_dataMatrix->m_ymin, m_dataMatrix->m_ymax));

Why is the value of my variable m _xmax equal to 3004.86, and the map shows a border greater than 3005, probably 3005.5?
Similarly with the left side.
https://ibb.co/BLTnZXx - this is a picture for better understanding.

    auto plot = ui->pCustomPlot;
    QSize size = m_dataMatrix->getSize();



    QCPColorMap *qMap = new QCPColorMap(plot->xAxis, plot->yAxis);

    qMap->data()->setRange(QCPRange(m_dataMatrix->m_xmin, m_dataMatrix->m_xmax), QCPRange(m_dataMatrix->m_ymin, m_dataMatrix->m_ymax));
    QVector<QVector<PointRS>> arr(m_dataMatrix->getMatrix());

    for (int i = 0; i < size.width(); i++)
        for (int j = 0; j < size.height(); j++)
            qMap->data()->setCell(i, j, arr[j][i].a);







see colormap->setTightBoundary

Thank you!

Sorry, but this method is not entirely correct. Boundary cells are cropped to half the cell size.

see https://blog.csdn.net/qq10097355/article/details/105741397

its don't help me

Look at the picture carefully :)

you need calc the halfCell width/height.

    QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower),
                              coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized();
    double halfCellWidth = 0;
    double halfCellHeight = 0;
    if (keyAxis()->orientation() == Qt::Horizontal) {
        if (mMapData->keySize() > 1)
            halfCellWidth = 0.5 * imageRect.width() / (double)(mMapData->keySize() - 1);
        if (mMapData->valueSize() > 1)
            halfCellHeight = 0.5 * imageRect.height() / (double)(mMapData->valueSize() - 1);
    } else {
        if (mMapData->keySize() > 1)
            halfCellHeight = 0.5 * imageRect.height() / (double)(mMapData->keySize() - 1);
        if (mMapData->valueSize() > 1)
            halfCellWidth = 0.5 * imageRect.width() / (double)(mMapData->valueSize() - 1);
    imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight);

Dmitry, the pixels of the color map are centered on the data coordinate, that makes sense. And then of course the color map is larger in each direction by half cell width/height. I don't see why that would be any different. If you fit the color map precisely in the range you specify, then the data points would be in wrong places.