Skip to content

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

Closed

Description

@michaelaye

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

Activity

  1. dmcdougall commented on Oct 3, 2012

    @dmcdougall
    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.

  2. michaelaye commented on Oct 3, 2012

    @michaelaye
    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.

  3. michaelaye commented on Oct 3, 2012

    @michaelaye
    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()
  4. dmcdougall commented on Oct 3, 2012

    @dmcdougall
    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.

  5. leejjoon commented on Oct 5, 2012

    @leejjoon
    Contributor

    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)
  6. pelson commented on May 22, 2013

    @pelson
    Member

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

  7. tacaswell commented on Jun 4, 2014

    @tacaswell
    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.

  8. modified the milestones: v1.4.x, v1.4.0 on Jun 4, 2014
  9. michaelaye commented on Jun 4, 2014

    @michaelaye
    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.

  10. modified the milestones: v1.4.x, on Feb 7, 2015
  11. modified the milestones: , on Jul 17, 2015
  12. tacaswell commented on Jul 17, 2015

    @tacaswell
    Member

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

  13. modified the milestones: , on Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions