y-axis misbehavior

I am on Ubuntu 11.10
matplotlib version 1.1.0
numpy version 1.5.1

I have two bar graph scripts (good.py and bad.py). Each generates a graph that contains two bars: one bar that extends along the positive y-axis and another bar that extends along the negative y-axis. The only difference between the two scripts is that in good.py the positive bar extends to 69.0, but in bad.py it extends to 70.0; however, while in good.py the y-axis ends precisely at -30.0, in bad.py the y-axis ends below -30.0 despite the yticks setting specified on line 20. Is there an explanation for this behavior? How might I remedy this?

bad.py (441 Bytes)

good.py (441 Bytes)

yticks() just sets the ticks, which shows up correctly in both plots. It sounds like what you want to specify is the axis limit. You can add the following (e.g. after the call to yticks):

plt.ylim(ymin=-30)

As for the reason, it has to do with creating axes sizes that fit all the elements within the plot area and also allow ticks that are “nicely” spaced. You just happen to be near the threshold of two different spacings, I think.

-Tony

···

On Thu, Jun 7, 2012 at 3:44 PM, Mark Gurling <magurling@…287…> wrote:

I am on Ubuntu 11.10
matplotlib version 1.1.0
numpy version 1.5.1

I have two bar graph scripts (good.py and bad.py). Each generates a graph that contains two bars: one bar that extends along the positive y-axis and another bar that extends along the negative y-axis. The only difference between the two scripts is that in good.py the positive bar extends to 69.0, but in bad.py it extends to 70.0; however, while in good.py the y-axis ends precisely at -30.0, in bad.py the y-axis ends below -30.0 despite the yticks setting specified on line 20. Is there an explanation for this behavior? How might I remedy this?

Mark Gurling:

I have two bar graph scripts (good.py and bad.py).

...

while in good.py the y-axis ends precisely at -30.0, in bad.py the y-axis ends below -30.0 despite the yticks setting specified on line 20. Is there an explanation for this behavior? How might I remedy this?

What do you really want?

Tony Yu tries to explain the behaviour.
I would suggest using an explicit axis, e.g.

plt.axis([0,0.10,-25,80])

(or between -30 and 100, or 'tight', etc.)
Perhaps you wanted axis('tight') rather than your tight_layout?

Jerzy Karczmarczuk

Tony Yu-3 wrote:

`yticks()` just sets the ticks, which shows up correctly in both plots. It
sounds like what you want to specify is the axis limit. You can add the
following (e.g. after the call to `yticks`):

   plt.ylim(ymin=-30)

Thanks Tony for clearing up my misunderstanding of what yticks() is doing.
Using ylim() gives me what I was after.

···

--
View this message in context: http://old.nabble.com/y-axis-misbehavior-tp33977870p33996062.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Jerzy Karczmarczuk-2 wrote:

What do you really want?

I just wanted the axis line to end at the last y tick

I would suggest using an explicit axis, e.g.

plt.axis([0,0.10,-25,80])

(or between -30 and 100, or 'tight', etc.)

I've never used an explicit axis. What will axis('tight') actually do?

Perhaps you wanted axis('tight') rather than your tight_layout?

I actually wanted tight_layout. good.py and bad.py were just my attempt to
reduce the problem to the fewest lines of code before posting it. The actual
problem script has a lot more going on and tight_layout works well in that
script for reasons unrelated to this problem. Sorry if I made things unclear
by leaving the tight_layout line in the scripts that I posted.

···

--
View this message in context: http://old.nabble.com/y-axis-misbehavior-tp33977870p33996132.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

In your case plt.axis('tight') will constrain the axes to your plotted object, no space above, below, or at the right. The "good" plot
gives x from 0 to 0.10, and y from -20.5 to 69. (The other: to 70).
The tight_layout directive is used mainly when you have several subplots.

Jerzy Karczmarczuk

···

Le 11/06/2012 22:30, magurling a écrit :

I just wanted the axis line to end at the last y tick

I've never used an explicit axis. What will axis('tight') actually do?