Discussion:
[Matplotlib-users] set_ylim() does not work with twinx()-axes
Willi Richert
2006-10-20 12:41:07 UTC
Permalink
Hi,

I am plotting two graphs in one according to
http://matplotlib.sourceforge.net/examples/two_scales.py

I want the plot belonging to the right axis to start with y=0. However,

ax2.set_ylim(ymin=0.0)

does not affect the plot at all.

Any hints?

Regards,
wr
John Hunter
2006-10-20 15:31:31 UTC
Permalink
Willi> Hi, I am plotting two graphs in one according to
Willi> http://matplotlib.sourceforge.net/examples/two_scales.py

Willi> I want the plot belonging to the right axis to start with
Willi> y=0. However,

Willi> ax2.set_ylim(ymin=0.0)

Willi> does not affect the plot at all.

It always helps to post a complete example; otherwise we have to use
our amazing powers of deduction to figure out what you might be doing
wrong. In this case, two possibilities come to mind:

1) you are calling set_ylim before a plot command and the autoscaler
is kicking on the plot command and overriding your changes. You
should call set_ylim after all plot commands, or turn autoscaling
off with the autoscale_on property of the Axes

2) you are working in interactive mode, eg ipython -pylab, and the
draw command is not being triggered since you are making an OO
call. You can force a draw command in pylab with "draw" or with
fig.canvas.draw().

The following *does* work for me, so maybe you can follow it as an
example

from pylab import *

ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')


# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
ax2.set_ylim(ymin=-3)
show()
Willi Richert
2006-10-21 17:56:28 UTC
Permalink
Post by John Hunter
from pylab import *
ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')
# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
ax2.set_ylim(ymin=-3)
show()
Hi,

this example does not work for me: Right axis is in the range [-1, 1].
(The same as the example two_axes.py with an additional set_ylim in my
previous mail. Sorry for the sparse information.)

matplotlib.__version__ == 0.82
python 2.4

Thanks,
wr
Eric Firing
2006-10-21 18:30:55 UTC
Permalink
Post by Willi Richert
Post by John Hunter
from pylab import *
ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')
# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
ax2.set_ylim(ymin=-3)
show()
Hi,
this example does not work for me: Right axis is in the range [-1, 1].
(The same as the example two_axes.py with an additional set_ylim in my
previous mail. Sorry for the sparse information.)
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.

Eric
Willi Richert
2006-10-23 07:55:42 UTC
Permalink
Post by Eric Firing
Post by Willi Richert
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.
Eric
Thanks. Unfortunately, I've not yet found a more recent ubuntu/dapper repo for
matplotlib. Any experience with installing the ubuntu edgy version (0.87) on
dapper?

Thanks,
wr
Sven Schreiber
2006-10-23 11:18:57 UTC
Permalink
Post by Willi Richert
Post by Eric Firing
Post by Willi Richert
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.
Eric
Thanks. Unfortunately, I've not yet found a more recent ubuntu/dapper repo for
matplotlib. Any experience with installing the ubuntu edgy version (0.87) on
dapper?
check out the ubuntu (dapper) section at
http://new.scipy.org/Installing_SciPy/Linux, that repository (by Andrew
Straw) also gives you recent matplotlib packages.
-sven
Willi Richert
2006-10-23 11:23:00 UTC
Permalink
Hi,

unfortunately, debs.astraw.com is not accessible.

wr@[ikarus]:~> ping debs.astraw.com
ping: unknown host debs.astraw.com

wr@[ikarus]:~> ping www.astraw.com
PING www.astraw.com (66.33.203.253) 56(84) bytes of data.
64 bytes from basic-emu.glass.dreamhost.com (66.33.203.253): icmp_seq=1 ttl=41
time=169 ms
Post by Sven Schreiber
Post by Willi Richert
Post by Eric Firing
Post by Willi Richert
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.
Eric
Thanks. Unfortunately, I've not yet found a more recent ubuntu/dapper
repo for matplotlib. Any experience with installing the ubuntu edgy
version (0.87) on dapper?
check out the ubuntu (dapper) section at
http://new.scipy.org/Installing_SciPy/Linux, that repository (by Andrew
Straw) also gives you recent matplotlib packages.
-sven
Eric Firing
2006-10-23 18:12:50 UTC
Permalink
With Linux it is easy to install matplotlib from the tarball or from
svn--no need to hunt around for a package.

Eric
Post by Willi Richert
Post by Eric Firing
Post by Willi Richert
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.
Eric
Thanks. Unfortunately, I've not yet found a more recent ubuntu/dapper repo for
matplotlib. Any experience with installing the ubuntu edgy version (0.87) on
dapper?
Thanks,
wr
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Willi Richert
2006-10-24 08:54:39 UTC
Permalink
Hi,

even with the newest version the problem remains, unless I put the set_ylim()
command _after_ plot(). Why?
Post by Eric Firing
Post by Willi Richert
Post by John Hunter
from pylab import *
ax1 = subplot(111)
t = arange(0.01, 10.0, 0.01)
s1 = exp(t)
plot(t, s1, 'b-')
xlabel('time (s)')
ylabel('exp')
# turn off the 2nd axes rectangle with frameon kwarg
ax2 = twinx()
s2 = sin(2*pi*t)
plot(t, s2, 'r.')
ylabel('sin')
ax2.yaxis.tick_right()
ax2.set_ylim(ymin=-3)
show()
Hi,
this example does not work for me: Right axis is in the range [-1, 1].
(The same as the example two_axes.py with an additional set_ylim in my
previous mail. Sorry for the sparse information.)
matplotlib.__version__ == 0.82
There is the problem: you need to update your matplotlib.
Eric
wr
John Hunter
2006-10-24 13:32:07 UTC
Permalink
Willi> Hi, even with the newest version the problem remains,
Willi> unless I put the set_ylim() command _after_ plot(). Why?

Quoting myself from my first post in this thread

1) you are calling set_ylim before a plot command and the autoscaler
is kicking on the plot command and overriding your changes. You
should call set_ylim after all plot commands, or turn autoscaling
off with the autoscale_on property of the Axes

Loading...