pylab: xlim with xscale

Greeting everyone,
In pylab (matplotlib 0.98.3.001 on Mac OS X) I've discovered that changing the xscale from linear to log removes the previously set xlim.

For example
In [1]: import pylab
In [2]: x = pylab.arange(100)
In [3]: y = pylab.sin(x)
In [4]: pylab.plot(x, y)
Out[4]: [<matplotlib.lines.Line2D object at 0x1a0981f0>]
In [5]: pylab.xlim(30, 50)
Out[5]: (30, 50)
In [6]: print pylab.xlim()
(30.0, 50.0)
In [7]: pylab.xscale('log')
In [8]: print pylab.xlim()
(1.0, 100.0)

There are easy workarounds, such as saving the axes before switching to log and restoring them after, but is this expected behavior?

Thanks,
Keoki

Keoki Seu wrote:

Greeting everyone,
In pylab (matplotlib 0.98.3.001 on Mac OS X) I've discovered that changing the xscale from linear to log removes the previously set xlim.

For example
In [1]: import pylab
In [2]: x = pylab.arange(100)
In [3]: y = pylab.sin(x)
In [4]: pylab.plot(x, y)
Out[4]: [<matplotlib.lines.Line2D object at 0x1a0981f0>]
In [5]: pylab.xlim(30, 50)
Out[5]: (30, 50)
In [6]: print pylab.xlim()
(30.0, 50.0)
In [7]: pylab.xscale('log')
In [8]: print pylab.xlim()
(1.0, 100.0)

There are easy workarounds, such as saving the axes before switching to log and restoring them after, but is this expected behavior?

An argument could be made either way, but I think the present behavior, in which autoscale_view is called after changing the scale, will cause the least surprise in the majority of cases. The default locator depends on the scale, and is used in the autoscaling process.

The suggested way of preventing the autoscaling (using pylab syntax to go with your example above) is to use "gca().set_autoscale_on(False)" before changing the scale.

Eric

···

Thanks,
Keoki

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks for the quick reply. Will this be documented anywhere? It would be nice for others to know the behavior of xscale.

Keoki

···

On Mar 3, 2009, at 12:19 PM, Eric Firing wrote:

An argument could be made either way, but I think the present behavior, in which autoscale_view is called after changing the scale, will cause the least surprise in the majority of cases. The default locator depends on the scale, and is used in the autoscaling process.