Question

I'm using a QwtPlotSpectrogram with a custom QwtRasterData to plot 2D data with widely varying values. I would like to plot using a logarithmic color scale instead of a linear one. Is there a simple way to do this?

My alternative is to feed log(value(x,y)) when QwtRasterData calculates the value. However, then my color bar will show the values in log, rather than the absolute values which is what I want - any suggestions there?

Thanks!

Was it helpful?

Solution

In case this is still interesting for anyone:

I had the same problem and wrote the following simple class:

class LogarithmicColorMap : public QwtLinearColorMap
{
public:
    LogarithmicColorMap(const QColor &from, const QColor &to)
        : QwtLinearColorMap(from, to)
    {
    }

    QRgb rgb(const QwtInterval &interval, double value) const
    {
        return QwtLinearColorMap::rgb(QwtInterval(std::log(interval.minValue()),
                                                  std::log(interval.maxValue())),
                                      std::log(value));
    }
};

And for the color bar you can use something like:

setAxisScaleEngine(QwtPlot::yRight, new QwtLog10ScaleEngine())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top