PDA

View Full Version : how to set width of the bars in QwtPlotHistogram?



penny
5th January 2011, 05:16
I'm using QwtPlotHistogram to plot data. I want to have a fixed size for the bars.
What happens is, that the bars use the entire QwtPlot area, so if i have less bars they expand and fit to the whole area, and if i have lots of bars, they shrink and squeeze in the area.
I want to keep constant width for the bars
How do i do that?

Uwe
5th January 2011, 06:30
A histogram displays ( x1-x2, y ) samples - this is not a bar chart. Maybe using a QwtPlotCurve in Sticks style is more what you are looking for.

Uwe

penny
5th January 2011, 06:58
I want to plot a histogram, but want to be able to define the width of the rectangles...

Uwe
5th January 2011, 08:53
I want to plot a histogram, but want to be able to define the width of the rectangles...
No you don't want to plot a histogram ( in the meaning of QwtPlotHistogram ) because in a histogram the width of the bars always corresponds to the x1-x2 interval on the x-axis !

If you want to control the width of the bars independent of the x axis scale you want to display a bar chart.

Uwe

penny
5th January 2011, 09:25
I think i'm not being able to write what i exactly want..
on my x axis, i have 0,1,2,3,4,....10 and on y axis i have 0,10,20,30..100
i want to plot
Interval Value
0-1 15
1-2 30
etc....
the width of all rectangles should and will indeed remain constant...
so my data is an array { 15,30,7,10,26,78,7 }
The problem is this:
If i give very few (say 5) values in the array, i get 5 rectanglesof a large width,
If i give lots of (say 50) values in the array, i get 50 rectangles of tiny width
The width of the rectangles increases or decreases according to the size of the data.

I have attached 2 plots showing the difference, (my x axis is vertical left, and y axis is horizontal top)
No matter what the size of my array, i want width of rectangles to remain same

Uwe
5th January 2011, 09:41
No matter what the size of my array, i want width of rectangles to remain same
When both plots have the same y axis scales ( not visible on your screenshots ), then your data class returns different intervals depending on whatever.

Uwe

penny
5th January 2011, 09:47
I'm sorry, but i don't understand what you mean..

Uwe
5th January 2011, 11:18
QwtPlotHistogram draws the bars according to the axis scales. When you have different columns widths for 2 plots with comparable canvas sizes then there are only 2 possible reasons:

- The axis scales are different
- The intervals of the samples are different

Uwe

penny
5th January 2011, 11:51
Thank You! :) I can manipulate it now using setAxisScale()
Thank you for hearing me out patiently!! :)