PDA

View Full Version : Can I set QwtPlot axis scale non-consecutive?



qmonkey
28th December 2010, 19:51
e.g. say I have a data set of 2000 points, but I only want to display x-axis scale of values in these ranges: [0, 100], [300, 500], [1900, 1999], in one qwtplot, is it possible?

d_stranz
30th December 2010, 17:54
So, are you saying you want the x-axis to show only the ranges [0,100],[300,500],[1900,2000) without a gap in between? (That is, 100 and 300 are right next to each other)?

This can be done, but it won't be easy. You will need to implement custom scale engine and scale draw classes for the X axis and substitute them for the default ones. The scale map class for the x-axis will be ugly, too, since every x value between 100 and 300 has to map to the same x pixel.

You might get some ideas looking at the histogram example.

Another way to maybe accomplish the same thing with much less work would be to stack multiple plots side-by-side, each one with only the small x sub-range needed. Make the y axis visible only for the left-most plot, and put the x-axis title only on the plot that is right-most (or maybe the center one, whatever you prefer).

You would need to synchronize the y-axes of all three plots so they had the same range, but otherwise the standard QwtPlotCurve code would take care of everything else.

If you don't want to have three copies of your data (one for each curve), make a QwtData object to wrap it and use that to get the data into the curves.

qmonkey
30th December 2010, 18:32
Thank you, d_stranz! Your assumption is correct. I adopted the same method as your second suggestion, it is the easiest way.