PDA

View Full Version : Axis not aligning with Spectrogram image



Ronayn
12th May 2010, 13:19
Hello,

I cant get the axis to align properly to the plot (see attached image). I'd like the ticks to be centered on the data bins -- not on the left side of the data bin. I've tried aligning the canvas to the axis, changing margins, and adjusting the axis -- all with no luck.

I am using Qwt5.2.0 on FC6. I can also post the code, if that would help -- but it was take almost verbatim from the spectrogram example code.

Uwe
13th May 2010, 08:50
Obviously your data bins cover squares with a size of 1, f.e one square is from 5-6, 10-11. So if you want to have a ticks centered its positions need to be 5.5, 10.5.

But I guess what you really want is a square at 4.5-5-5, 9.5.10.5 - probably by using qRound() instead of floor ( = casting to int ) in YourRasterData::value().

Uwe

PS: If the resolutions of your data is 1x1 don't forget to implement YourRasterData::rasterHint(). It will make the rendering process much faster.

Ronayn
14th May 2010, 11:13
Obviously your data bins cover squares with a size of 1, f.e one square is from 5-6, 10-11. So if you want to have a ticks centered its positions need to be 5.5, 10.5.

But I guess what you really want is a square at 4.5-5-5, 9.5.10.5 - probably by using qRound() instead of floor ( = casting to int ) in YourRasterData::value().

Uwe

PS: If the resolutions of your data is 1x1 don't forget to implement YourRasterData::rasterHint(). It will make the rendering process much faster.

Thanks for your reply Uwe. I modified my code to use qRound -- I also had to change the axis and the spectrograms bounding rect. The attached plot shows the result (it looks good!).

I dont quite understand your advice about rasterHint -- very much a graphics novice here. I am going to look through the examples to see if I can figure out what you mean. Btw, each data point (bin) of my data should be square (though I can live with rectangles!).

Uwe
15th May 2010, 18:48
I dont quite understand your advice about rasterHint -- very much a graphics novice here..
Obviously your data has a resolution of 1.0x1.0 and the image above could be rendered with something about 35x48 ( = 1680 ) values.

Without any information about the resolution YourData::value() has to be called for each position corresponding to a pixel. F.e. for a widet with 1000x1000 pixels it means 1000000 values will be collected to render the ~same image. When printing in high resolution you will have even much more points ...


Btw, each data point (bin) of my data should be square (though I can live with rectangles!).
The ratio of your rectangles always corresponds to your scales. Have a look at QwtPlotRescaler ( in svn trunk you find an example called "navigation" using it ) if you want to set a fixed ratio ( f.e 1:1 ). It is a helper, that tries to auto-adjust the scales according to the size of the plot canvas.

Uwe