Skip to content

axes limits revert to automatic on sharing axes? #10062

Closed
@gregcolyer

Description

@gregcolyer

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions