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

BUG: Add subplot spec eq #2597

Merged
merged 5 commits into from Dec 18, 2013
Merged

Conversation

tacaswell
Copy link
Member

See: http://stackoverflow.com/questions/20017314/how-are-existing-subplot-axes-retrieved-using-subplot2grid-gridspec-in-matplotli

in short,

gs = gridspec.GridSpec(2,1)
In [220]: gs[0, 0] == gs[0, 0]
Out[220]: False

which breaks the logic of calling ax = fig.add_subplot(gs[0,0]) multiple times.

This is to address the issue discovered in
http://stackoverflow.com/questions/20017314/how-are-existing-subplot-axes-retrieved-using-subplot2grid-gridspec-in-matplotli
where multiple calls to

   gs = gridspec.GridSpec(2, 1)
   ax1 = fig.add_subplot(gs[0, 0])
   ax2 = fig.add_subplot(gs[0, 0])

will return a new axes each time (unlike calls integers or tuples).
@tacaswell
Copy link
Member Author

And this seems to break all sorts of things and I have no idea why.

@mdboom
Copy link
Member

mdboom commented Nov 18, 2013

I suspect a lot of these failures can be fixed by putting isinstance(other, SubplotSpec) (or hasattr(other, '_gridspec') if we'd rather do duck typing) to the beginning of the expression. I don't know if that will fix everything else.

@tacaswell
Copy link
Member Author

The other way to do this would be to wrap the all in a try...except not sure which way is preferred.

@Tillsten
Copy link
Contributor

There is sometimes a real need of getting a different axes at the same place: twinx etc.
So this should be at least doable with a keyword, which means i am not sure which default behavior makes
more sense.

@Tillsten
Copy link
Contributor

Ahh, i see that doable by #2515, than nvm :)

@tacaswell
Copy link
Member Author

And, again I get errors on python 3 that I do not really understand. Lets see if adding __hash__ makes things better....

@Tillsten I am confused, #2515 is change in mpl_toolkits which makes divided axes play nice with twinx and is (I think) completely orthogonal to this one.

@Tillsten
Copy link
Contributor

@tacswell Oh, i maybe i read #2515 too fast. I used the old behavior to make my own twinx with gs, but now it seems it was never necessary. Sorry for the noise.

@pelson
Copy link
Member

pelson commented Dec 9, 2013

@tacaswell - nice easy one to test. If you can add a unit test, I will merge. 👍

Added test to check if repeated calls to to `gs[n, m]` are
equal.
@tacaswell
Copy link
Member Author

@pelson test added.

pelson added a commit that referenced this pull request Dec 18, 2013
@pelson pelson merged commit 3284b17 into matplotlib:v1.3.x Dec 18, 2013
@tacaswell tacaswell deleted the add_SubplotSpec__eq__ branch December 18, 2013 14:25
@duckrojo
Copy link

This is an old bug, but it seems it has not been corrected? I still get a new axes instances instead of referring an existing axes; or am I missing anything?

@tacaswell
Copy link
Member Author

@duckrojo what version of mpl are you using?

The tests added in this PR are still in the code base (and being run by our CI) Can you provide a MWE of what is broken?

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

Successfully merging this pull request may close these issues.

None yet

5 participants