Vertical bar - making the bar fixed width

So, if I understand correctly, this is a cosmetic issue: If you let it sort out its own scale, it looks a bit ugly when there are a small number of data points? And using a fixed re-scale of 0-10 isn't too great either 'cause they're all together at one side of the image... (or off the edge of it if there are more than 10 points)

With the normal caveat that my suggestion is unlikely to the best way of doing it, how about:

If there are less than some number of datapoints, say 5, move the datapoints to higher x and rescale the axis, if there are more than 5, let matplotlib handle everything automatically:

ind = arange(N, dtype=float) # the x locations for the groups
if N < 5.0:

     ind += (5.0-N)/2.0 # Slide the x points up

# draw the bars here

if N < 5:
     xlim(0, 5) # Rescale

If you do this I think (but I haven't checked) you'll also need to change:

     for i in xrange(N):
         text(i, 0, " %s" etc...)

to:

     for i in ind:
  text(i, 0, etc...)

in order to keep the text lined up right.

Hope that helps,

Fred

Alen Ribic wrote:

···

Thanks again Fred. Its looking much better now. However, one last
related thing, the x axis plots are not centered in the middle. Now
they are left aligned. For example, If there are only 1 or 2 plots on
the x axis, they get displayed from the 0, origin point, the immediate
left of the graph. How do I, if possible, have the x plots centered in
the middle of the graph?

I just saw an example that seems to have the x plots centered. Here is
the link to it.
http://matplotlib.sourceforge.net/screenshots.html

Its the table_demo.py example.

I have also attached the code if you don't mind having a quick look.

Much appreciated,
-Alen

On 8/24/07, Fred Ludlow <rfl26@...776...> wrote:

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.

-------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks again Fred. With a bit of adjustment as per your helpful info
below, I got the bars to align, cosmetically, just as I hoped.

-Alen

···

On 8/25/07, Fred Ludlow <rfl26@...776...> wrote:

So, if I understand correctly, this is a cosmetic issue: If you let it
sort out its own scale, it looks a bit ugly when there are a small
number of data points? And using a fixed re-scale of 0-10 isn't too
great either 'cause they're all together at one side of the image... (or
off the edge of it if there are more than 10 points)

With the normal caveat that my suggestion is unlikely to the best way of
doing it, how about:

If there are less than some number of datapoints, say 5, move the
datapoints to higher x and rescale the axis, if there are more than 5,
let matplotlib handle everything automatically:

ind = arange(N, dtype=float) # the x locations for the groups
if N < 5.0:

     ind += (5.0-N)/2.0 # Slide the x points up

# draw the bars here

if N < 5:
     xlim(0, 5) # Rescale

If you do this I think (but I haven't checked) you'll also need to change:

     for i in xrange(N):
         text(i, 0, " %s" etc...)

to:

     for i in ind:
        text(i, 0, etc...)

in order to keep the text lined up right.

Hope that helps,

Fred

Alen Ribic wrote:
> Thanks again Fred. Its looking much better now. However, one last
> related thing, the x axis plots are not centered in the middle. Now
> they are left aligned. For example, If there are only 1 or 2 plots on
> the x axis, they get displayed from the 0, origin point, the immediate
> left of the graph. How do I, if possible, have the x plots centered in
> the middle of the graph?
>
> I just saw an example that seems to have the x plots centered. Here is
> the link to it.
> http://matplotlib.sourceforge.net/screenshots.html
>
> Its the table_demo.py example.
>
> I have also attached the code if you don't mind having a quick look.
>
> Much appreciated,
> -Alen
>
>
> On 8/24/07, Fred Ludlow <rfl26@...776...> wrote:
>> 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.
>>
>> -------------------------------------------------------------------------
>> 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
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>

-------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users