Skip to content

axes limits revert to automatic on sharing axes? #10062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gregcolyer opened this issue Dec 20, 2017 · 5 comments
Closed

axes limits revert to automatic on sharing axes? #10062

gregcolyer opened this issue Dec 20, 2017 · 5 comments
Milestone

Comments

@gregcolyer
Copy link

Sharing axes undoes manual limits, but they can be restored afterwards.

The script below initially has manual limits on the first (and only) subplot. After uncommenting just the lines below 1, the manual limits are lost (on both subplots). After uncommenting the lines below 2, they are restored (on both subplots). It may be by design, but is a gotcha for users because usually (without axis sharing) the limits are not sensitive to where they are set (e.g. before or after calling contour). The sensitivity to placement with shared axes does not seem to be easily found in the documentation.

matplotlib 2.0.0 via conda

import matplotlib.pyplot as plt
import numpy as np

p = np.arange(100,1000,100)
l = np.arange(-80,90,40)
t = np.random.random_sample((p.size,l.size))

plt.figure()

ax1 = plt.subplot(221)
ax1.set_xlim(-90,90)    ## Set manual limits
ax1.set_ylim(1000,0)    ##
c1 = ax1.contour(l,p,t)

# 1. Adding a second subplot reverts to automatic limits on both subplots ...
#ax2 = plt.subplot(223,sharex=ax1,sharey=ax1)
#c2 = ax2.contour(l,p,t)

# 2. ... unless set manual limits after
#ax1.set_xlim(-90,90)
#ax1.set_ylim(1000,0)

plt.show()
@jklymak
Copy link
Member

jklymak commented Dec 20, 2017

Its possible that the logic in cla could be changed to let this happen. Right now auto gets set to None, but you probably want it set to self._sharex.get_autoxscale() I'm not sure what the knock-on effects might be of that change however.

if self._sharex is not None:
# major and minor are class instances with
# locator and formatter attributes
self.xaxis.major = self._sharex.xaxis.major
self.xaxis.minor = self._sharex.xaxis.minor
x0, x1 = self._sharex.get_xlim()
self.set_xlim(x0, x1, emit=False, auto=None)
self.xaxis._scale = mscale.scale_factory(
self._sharex.xaxis.get_scale(), self.xaxis)

@lkjell
Copy link
Contributor

lkjell commented Dec 23, 2017

It is not sharing axes that breaks the datalim it is the contourplot. Can check with
print(ax1.get_xlim())

Anyway in def contour you have self.autoscale_view() called.

@jklymak
Copy link
Member

jklymak commented Dec 23, 2017

I believe that ax1.autoscale_view() doesn't do anything if set_xlim has been called because ax1._autoscaleXon is False. The problem is that when ax2 gets added as a twin, it has self._autoscaleXon of True, the axes limits are reset fo ax2, but its twinned, so ax1 also gets reset to the auto limits. The OP is arguing that if ax1._autoscaleXon is False, it should be False for ax2 as well.

shaynair pushed a commit to shaynair/matplotlib that referenced this issue Mar 15, 2018
@phobson
Copy link
Member

phobson commented Mar 30, 2018

closed via #10798

@phobson phobson closed this as completed Mar 30, 2018
@QuLogic QuLogic added this to the v3.0 milestone Mar 30, 2018
@gregcolyer
Copy link
Author

@shaynair Thank-you for addressing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants