Search code examples
loggingscaleqwt

Qwt: log scale and ticks every 10th of a decade


I made a QwtPlot with an x log scale and a y linear scale. The x axis range is fixed from 10 to 1000, i.e. 3 decades. A added a grid with major and minor divisions.

The problem : the minor ticks fall at some automatically calculated positions.

What I want : a minor tick every 10th of a decade (20, 30, ..., 200, 300, ...).

I tried to play around, following various examples found here and there. But anything I tried didn't change a thing. I'm sure I missed something in Qwt's documentation...

Qwt version : 6.1.4


Solution

  • I figured it out. In a subclass of QwtPlot :

    setAxisAutoScale(QwtPlot::xBottom, false);
    xlogScale = new QwtLogScaleEngine();
    QwtScaleDiv xDiv = xlogScale->divideScale(10.0, 1000.0, 2, 10, 1.0);
    setAxisScaleEngine(QwtPlot::xBottom, xlogScale);
    setAxisScaleDiv(QwtPlot::xBottom, xDiv);
    

    The key is the 3rd line, which sets the x axis scale. For some reason, I had trouble to understand what arguments the function expects :

    • from 10 to 1000
    • 2 major steps
    • 10 minor steps per decade
    • major step size = 1 decade

    And also, don't call QwtPlot::setAxisScale() ! It resets everything to default.

    Hope it helps !

    enter image description here