PDA

View Full Version : Using logaritmic and linear axis scale together



alperyazir
14th July 2014, 08:28
Hey !

I am using qwt 6.1.0. I tried:

linEngine = new QwtLinearScaleEngine;

logEngine = new QwtLogScaleEngine;

these codes to make my axis logaritmic and linear. But I want use them together for examle;

1 - 10 ---> in this interval must be linear

10 - 10000 ---> in this interval must be logaritmic

10517

is that possible?

Uwe
15th July 2014, 08:40
You can try something like this:


class MyTransform: public QwtTransform
{
public:
MyTransform( double threshold ):
m_threshold( threshold ),
m_offset( threshold - log( threshold ) )
{
}

virtual double transform( double value ) const
{
double v = qAbs( value );
if ( v > m_threshold )
v = m_offset + log( v );

return value < 0.0 ? -v : v;
}

virtual double invTransform( double value ) const
{
double v = qAbs( value );
if ( v > m_offset )
v = qExp( v ) - m_offset;

return value < 0.0 ? -v : v;
}

virtual double bounded( double value ) const
{
return value;
}

virtual QwtTransform *copy() const
{
return new MyTransform( m_threshold );
}

private:
const double m_threshold;
const double m_offset;
};

...
QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
scaleEngine->setTransformation( new MyTransform( 10.0 ) );
plot->setAxisScaleEngine( QwtPlot::yLeft, scaleEngine );

QwtScaleDiv scaleDiv( -10000.0, 10000.0 );

QList<double> majorTicks;
majorTicks << -10000 << -1000 << -100 << -10 << -8 << -6 << -4 << -2 << 0 << 2 << 4 << 6 << 8 << 10 << 100 << 1000 << 10000;
scaleDiv.setTicks( QwtScaleDiv::MajorTick, majorTicks );

plot->setAxisScaleDiv( QwtPlot::yLeft, scaleDiv );


If you can't set the ticks manually ( f.e. your application supports zooming ) you also have to implement your own type of QwtScaleEngine.

Uwe