-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Auto-scaling of extent not working for subplots when using sharex and sharey #1325
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
Comments
Thanks for this @michaelaye. Apologies for the messy advice on the mailing list. Did you manage to get the workaround functional? Hopefully this can get some visibility before the 1.2 release. Thanks again. |
Not really (see feedback on the mailing list.) Your example that way fails to set the extent as well. So I will add it here as another way to reproduce. |
The following code with the setting of an extent at the end fails to work for me as well. As a side, it also does not share the x and y axis. import matplotlib.pyplot as plt
from numpy import arange, array
arr = arange(10000).reshape(100,100)
l = [arr,arr,arr,arr]
narr = array(l)
axes = []
fig = plt.figure()
for i in range(4):
if i == 0:
axes.append(fig.add_subplot(2, 2, i))
if i > 0:
axes.append(fig.add_subplot(2, 2, i, sharex=axes[0], sharey=axes[0]))
for ax, im in zip(axes, narr):
ax.imshow(im, extent=[0,100,0,100])
plt.show() |
The sharing is working for me, but the extent isn't set right in that example either. Actually, that example is diagnostically helpful. Cheers for posting it. |
shared_axes and aspect=1 does not play along well . If both parameters are set, matplotlib changes the adjustable parameter to "datalim" (default is "box"). And when the aspect is applied during the drawing time, it changes the data-limits (not box size). If you have both x- and -y axes are shared and all the shared axes have aspect=1, you can change the adjustable to "box-forced" which will work as expected. for ax,im in zip(axes.flatten(),narr):
ax.set_adjustable("box-forced")
ax.imshow(im) |
@michaelaye - did @leejjoon 's suggestion work for you? |
Punting this to (at least) 1.4.x as this is an issue with too many constraints on the limits not playing nice with each other/having unclear precedence/hysteresis. |
Sorry for not having answered above. @leejjoon 's workaround does work for me, even showing the sharing of the axes work. I don't remember why we had such a inflated example though. These days I would just do: fig, axes = subplots(nrows=2, ncols=2, sharex=True, sharey=True)
arr = arange(10000).reshape(100,100)
for ax in axes.flatten():
ax.set_adjustable('box-forced')
ax.imshow(arr)
show() Was there no subplots available in Oct 2012? Time flies... Edit: Ah, my bad. it was the distinction between subplots and add_subplot that was the essence of this bug in the first place. |
Closing as the |
Using MPL 1.1.0 from the 32-bit EPD 7.3-2 on a Macbook Pro Retina.
This error only shows when using subplots. When creating your own sublots via add_subplot it does not seem to occur.
Expected vs Seen:
One can see that all the 4 axes show the image array with an extent of [-10,110, 0, 100] here instead of the expected intent of [0,100, 0, 100].
The text was updated successfully, but these errors were encountered: