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

undefined behavior of figure.add_subplot() once subplot is modified. #429

Closed
yannpaul opened this issue Aug 19, 2011 · 6 comments
Closed

Comments

@yannpaul
Copy link
Contributor

Modifying a subplot using change_geometry() method does not update the corresponding key for the subplot in the figure. So when you call add_subplot(), you need to call it with the original _args and *_kwargs not the modified ones, if you want to access the already existing subplot.

This was identified in matplotlib version 0.99.1.1, but looking at the current code in github, it appears the same behavior exists.

@efiring
Copy link
Member

efiring commented Aug 19, 2011

I am inclined to think that the whole business of keeping a key and allowing add_subplot() to return an existing axes if the key is matched is a mistake--extra complexity for minimal gain. Is there a major use case for this that would be substantially more difficult to handle without it?

@c00kiemonster
Copy link

I agree with efiring, wouldn't it be better to simply separate the {add,get}_subplot functionality? Whenever I use add_subplot I need to put in extra logic to check that new axes haven't been created. It doesn't exactly lead to nice looking code.

@pelson
Copy link
Member

pelson commented Jun 6, 2012

I agree.

More evidence that keeping track of the axes via hash, at all, is hard (and error prone):

>>> import matplotlib.pyplot as plt
>>> ax = plt.subplot(121, projection='polar')
>>> ax_via_gca = plt.gca(projection='polar')
>>> ax_via_gca is ax
False

@tacaswell
Copy link
Member

I am closing this because it seems to be fixed (@pelson 's example now returns True). Please re-open if this is still an issue.

@pelson
Copy link
Member

pelson commented Jan 27, 2014

Cool. Thanks for spotting @tacaswell - I think I might have fixed this some time ago between v1.1 and v1.2 to aid in the Cartopy interfacing.

@AeroEngy
Copy link

This issue doesn't seem to be fixed... Or it cropped back up since this one is pretty old. See this stackoverflow link for an example. http://stackoverflow.com/questions/31600726/matplotlib-add-subplot-change-geometry-bug

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