QCustomPlot Discussion and Comments

Problems with Color Gradient/Color ScaleReturn to overview
November 20, 2025, 11:03
by David Partridge

I emailed this in but am also going to post it here.

I can't get QCPColorMap to quantise the data.

colorMap->setDataRange(QCPRange(*p.first, *p.second));
colorScale->axis()->setLabel("FWHM");
//
// Update the color map with FWHM values from the interpolated grid
//
for (size_t i = 0; i < xg.size(); ++i)
{
 for (size_t j = 0; j < yg.size(); ++j)
 {
 colorMap->data()->setCell(static_cast<int>(xg[i]), static_cast<int>(yg[j]), zg[i + j * xg.size()]);
 }
}
QCPColorGradient gradient(QCPColorGradient::gpSpectrum);
gradient.setNanHandling(QCPColorGradient::nhTransparent);
gradient.setLevelCount(10);
//gradient.loadPreset(QCPColorGradient::gpSpectrum);
colorMap->setGradient(gradient);
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 (default)
colorScale->setDataRange(colorMap->dataRange());
colorMap->setColorScale(colorScale); // associate the color map with the color scale

Doesn’t set the gradient as I expect – what I see is: a graph with the gpCold scheme and smooth colour changes rather than quantised changes

What am I doing wrong?
Thanks, David

AltStyle によって変換されたページ (->オリジナル) /