Search code examples
c++qtqwt

Qwt rescale axis


I have a QwtPlot that I wish to alter the axis scale without having to change the value of the points drawn themselves.

In my application I plot points in Volts, inside a [-10,10] V range (both axes). I'd like to calibrate each axis by multiplying it by a value in nm/V to convert the scale to nanometers. I'd like to do this without having to alter the value of the points themselves. What would be the most pratical way of getting this done?

Thanks


Solution

  • qwt is not going to allow you to change the axis values without affecting the data. What you can do however, is change the axis labels. This will give you the apparent scaling affect you are looking for, but without having to manipulate your data at all.

    class QConversionScaleDraw : public QwtScaleDraw
    {
    public:
    
        explicit QConversionScaleDraw(double conversionFactor)
        : m_conversionFactor(conversionFactor)
        {
    
        }
    
        virtual QwtText label(double value) const override;
        {
            return QwtScaleDraw::label(value * m_conversionFactor);
        }
    
    private:
    
        double m_conversionFactor;                                                
    
    };
    

    Then to use it:

    QwtPlot myplot;
    double nmToV = 0.612; // or whatever
    myplot->setAxisScaleDraw(xBottom, new QConversionScaleDraw(nmToV));