Vertical bar - making the bar fixed width

Thanks Fred.

Thant did the trick. However now, when I have many plots on x axis,
the last few plot shoot of the end of the x axis. It seems to start
the plotting the middle move to the right. Do I just have to adjust
the xlim on the axes[0]? I fiddled with the "align" parameter, set it
to "center", on the bar function and it didn't do much.

-Alen

···

On 8/24/07, Fred Ludlow <rfl26@...776...> wrote:
> Alen Ribic wrote:
> > How do I set my vertical bar to be fixed width?
>
> By default, bars are created with a fixed width of 0.8, which can be
> changed with the width keyword arg like so:
>
> bar(range(2), range(1,3), width = 0.5)
>
>
> > Depending on amount of data on my x axis, the bars get created
> > accordingly and the width gets adjusted to fit into the graph.
> The width in pixels/proportion of axis is dependent on the range of the
> x-axis, which you can set manually too.
>
> There's probably a more elegant way of doing this, but here's a quick
> and dirty method for interactive mode (ipython/pylab):
>
> # Make a figure, catch the reference as f
> f = figure(1)
>
> # Draw some bars
> bar_list = bar(array([0,0.5,1.0]), array([1.0,2.0,3.0]), width = 0.25)
>
> # Get the subplot (f.axes is a list containing the subplots)
> s = f.axes[0]
>
> # Set the x-axis limits of the subplot
> s.set_xlim((-5.0, 5.0))
>
> # Redraw
> draw()
>
>
> Fred
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options
>

Alen Ribic wrote:

Thanks Fred.

Thant did the trick. However now, when I have many plots on x axis,
the last few plot shoot of the end of the x axis. It seems to start
the plotting the middle move to the right. Do I just have to adjust
the xlim on the axes[0]? I fiddled with the "align" parameter, set it
to "center", on the bar function and it didn't do much.

-Alen

Hi Alen,

The align parameter sets whether the left, or the center of the bar should be aligned with the x-value you give for that bar. So the right hand edge of the bar would be at x+width (or x + (width/2) for center), and you'd need to set x_lim to include this. If I've misunderstood your problem can you post the code that's causing trouble?

Cheers,

Fred

ps.
gca() also gets the current axes object, which is marginally less typing than what I said before, so you can use:

gca().set_xlim([0.0, 10.0])
draw()

to re-scale the x-axis on the last thing you plotted to 0.0-10.0.