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

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

Comments

Projects
None yet
6 participants
@yannpaul
Contributor

yannpaul commented Aug 19, 2011

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

This comment has been minimized.

Show comment
Hide comment
@efiring

efiring Aug 19, 2011

Member

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?

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

This comment has been minimized.

Show comment
Hide comment
@c00kiemonster

c00kiemonster Aug 19, 2011

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.

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

This comment has been minimized.

Show comment
Hide comment
@pelson

pelson Jun 6, 2012

Member

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

This comment has been minimized.

Show comment
Hide comment
@tacaswell

tacaswell Jan 16, 2014

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.

Member

tacaswell commented Jan 16, 2014

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.

@tacaswell tacaswell closed this Jan 16, 2014

@pelson

This comment has been minimized.

Show comment
Hide comment
@pelson

pelson Jan 27, 2014

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@AeroEngy

AeroEngy Jul 24, 2015

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

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