Pavel Strakhov
Pavel Strakhov

Reputation: 40492

QwtPlot custom axis

I want to create plot with two horizontal axes. Bottom axis is linear, top axis is non-linear. I have a table of data for conversion "Bottom value -> top value". I found out that QwtScaleEngine provides this functionality. But I can't make it work because there're too many badly documented functions to define in subclasses of QwtScaleEngine and QwtScaleDiv.

Any suggestions?

Upvotes: 4

Views: 2428

Answers (1)

Knut Vidar Siem
Knut Vidar Siem

Reputation: 96

Do you want two horizontal axes to effectively overlay two plots that share an axis, or just to provide an additional representation (e.g. different unit) of the first horizontal axis? It might not be all that relevant, I'm just trying to understand your problem.

I would first recommend you have a look at the QwtPlot::updateAxes() documentation. It is the best description I have found of the relationship between a plot, scale engines and scale divisions in the official Qwt documentation. While I don't think Qwt is badly documented, I do think it lacks a high-level description of the concepts.

QwtScaleDiv I see as more of a container type, containing the axis boundaries and potentially the tick values. I can't see that it is necessary for you to subclass QwtScaleDiv.

You are correct that QwtScaleEngine is involved in this conversion, but there is a little more to it, at least in Qwt 6.1.0. QwtScaleEngine supports a transformation concept (QwtTransform) with setTransformation(). If your conversion is a simple mathematical function such as a logarithmic, exponential, quadratic, cubic function etc, you should be able to use QwtPowerTransform or QwtLogTransform. If these aren't applicable you can implement your own QwtTransform and assign it to a QwtScaleEngine. As far as I know, the transformation must be two-way, meaning implementing both transform and invTransform. In my experience it must also transform values for all plot items associated with the axis that the scale engine is associated with, including grid lines, zones etc. I have not tried using transformations on other scale engines than the default QwtLinearScaleEngine, but that has worked great. It's a powerful concept. Also, have a look at the scaleengine example in the SVN playground (6.1.0).

Upvotes: 1

Related Questions