PDA

View Full Version : Changing the scale of axis in a plot



rradjabi
14th October 2015, 00:41
Hello,

I have a Qwt plot that displays the X-Axis in units of digital samples. My data series is 10 samples for example, data = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]. My x-axis actually corresponds to a length in mm, where 10 Samples = 3 mm. How can I draw the axis so the same data is plotted, but I display a different scale? See the example graph I've drawn below. In reality, I have 512 Samples that correspond to ~3 mm, but I believe this is effectively the same.

Thank you in advance!
Ryan





plotting data that consists of 10 samples
data = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]

110 + : : : : : : : : : :
100 + : : : : : : : : x :
90 + : : : : : : : x : :
80 + : : : : : : x : : :
70 + : : : : : x : : : :
60 + : : : : x : : : : :
50 + : : : x : : : : : :
40 + : : x : : : : : : :
30 + : x : : : : : : : :
10 + x : : : : : : : : :
10 x : : : : : : : : : :
0 --+--+--+--+--+--+--+--+--+--+--+
| | | | | | | | | | |
0 2 4 6 8
(Samples)




Draw X Axis to a new scale where 10 Samples = 3 mm

0 S => 0 mm
1 S => 0.3 mm
2 S => 0.6 mm
3 S => 0.9 mm
.
.
.
9 S => 2.7 mm
110 + : : : : : : : : : :
100 + : : : : : : : : x :
90 + : : : : : : : x : :
80 + : : : : : : x : : :
70 + : : : : : x : : : :
60 + : : : : x : : : : :
50 + : : : x : : : : : :
40 + : : x : : : : : : :
30 + : x : : : : : : : :
10 + x : : : : : : : : :
10 x : : : : : : : : : :
0 --+--+--+--+--+--+--+--+--+--+--+
| | | | | | | | | | |
| | | | |
0 0.6 1.2 1.8 2.4
(mm)

Uwe
14th October 2015, 08:17
Well, a curve displays a series of points - not values - so I guess your code adds the index as x coordinate. And now you want to use index * 0.3 as x coordinates ?

Uwe

rradjabi
14th October 2015, 18:55
Hi Uwe,

I think my answer to your question is yes. Let me clarify. I do not want to change the data in the plot, I just want to change the label of the X-axis. I also want to continue to plot the same number of samples.

Ryan

Uwe
15th October 2015, 00:58
Derive from QwtScaleDraw, overload the label() method and pass it with QwtPlot::setAxisScaleDraw().

Uwe