Skip to content
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

Auto-scaling of extent not working for subplots when using sharex and sharey #1325

Closed
michaelaye opened this issue Oct 3, 2012 · 9 comments

Comments

@michaelaye
Copy link

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.

from matplotlib.pyplot import show, subplots
from numpy import arange, array

arr = arange(10000).reshape(100,100)
l = [arr,arr,arr,arr]
narr = array(l)

fig, axes = subplots(2,2,sharex=True,sharey=True)

for ax,im in zip(axes.flatten(),narr):
    ax.imshow(im)

show()

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].

@dmcdougall
Copy link
Member

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.

@michaelaye
Copy link
Author

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.

@michaelaye
Copy link
Author

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

@dmcdougall
Copy link
Member

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.

@leejjoon
Copy link
Contributor

leejjoon commented Oct 5, 2012

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)

@pelson
Copy link
Member

pelson commented May 22, 2013

@michaelaye - did @leejjoon 's suggestion work for you?

@tacaswell
Copy link
Member

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.

@tacaswell tacaswell modified the milestones: v1.4.x, v1.4.0 Jun 4, 2014
@michaelaye
Copy link
Author

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.

@tacaswell tacaswell modified the milestones: v1.4.x, 1.5.0 Feb 7, 2015
@tacaswell tacaswell modified the milestones: proposed next point release, next point release Jul 17, 2015
@tacaswell
Copy link
Member

Closing as the set_adjustable fixes the problem and the default behavior looks like a feature not a bug.

@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants