Vertical bar - making the bar fixed width

How do I set my vertical bar to be fixed width? Depending on amount of
data on my x axis, the bars get created accordingly and the width gets
adjusted to fit into the graph. If I have only 2 plots on the x axis
then the 2 bars get stretched across the entire graph. Looks very
ugly.

-Alen

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