2

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

Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
A. Vieira
  • 1,213
  • 2
  • 11
  • 27
  • http://qwt.sourceforge.net/class_qwt_plot.html#acef5ea818944b93b8695d0c16924eed6 –  Apr 18 '16 at 12:55
  • The QwtPlot::setAxisScale() rescales both the axis and the plot region as well. I need to change the values in the axis but leave the plot in the same region. This means that the points on the plot show up in the same place but the axis has diferent values. – A. Vieira Apr 18 '16 at 14:16
  • You can't change the axes values without moving the data around. You either have to a) scale the data (which I'm assuming is too inefficient for you), or b) scale the axis _label values_ – Nicolas Holthaus Apr 18 '16 at 15:31
  • I had a similar problem with disabling scientific notation on the scale, you'd have to do something similar (subclass `QwtScaleDraw`) to do your nm/V scaling: http://stackoverflow.com/questions/32761035/qwt-turn-off-scientific-notation-for-axis-labels – Nicolas Holthaus Apr 18 '16 at 15:35

1 Answers1

2

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));
Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97