You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Autoscale does not work for artists added with Axes.add_artist #2202
Adding an artist through Axes.add_artist() does not update the data limits of the plot, so autoscale does not work.
ax=gca()
circ=Circle((0,0), 5)
ax.add_patch(circ) #autoscale works for this#ax.add_artist(circ) #autoscale does not work for thisax.relim() # not strictly necessaryax.autoscale(True)
plt.show()
I think this is by design. add_artist isn't really intended for data, but for annotations to the data. But we should probably improve the docs on this point.
OK. Sounds like I've been trying to use it incorrectly. I was trying to lazily send artists to add_artist rather than identifying which ones are patches and which are lines. Things work OK when I send the Artist to its specific add method.
Clearer docs would be a big plus. I'd try to help, but I'm not clear on the function/intention myself: artists sent to add_artist are drawn to the Axes, but are excluded from relim and hence autoscale? If this is the idea, it seems nicer to:
have an optional argument to add_artist where you could specify relim=False
or
better yet, add this as an attribute the Artist itself.
Are there really use cases where people don't want plots to rescale to include annotations?
I found myself fighting with this issue today. I agree with @hohlraum: I think use-cases where people don't want plots to rescale to include annotations are very much the edge-case.
Seconding @brianthelion, it took me half an hour to find out that axes with an Ellipse added byadd_patch() are rescaled correctly, but not when I use add_artist(). I recommend it be fixed.
Internally Axes objects maintain several lists of of Artists objects that have been added to it based on the type of artist.
Currently relim only takes into account self.patches and self.lines. Changing it so that relim would also take into account se!f.artists would be a backwards incompatible change.
Sorry just one question for completeness very related to this topic. How can I then paste an image at a specific position on a given axes (which also contains an image)? I mean I was using OffsetImage in combination with AnnotationBbox but I noticed their reference frames are independent and thus (e.g.) resizing only works for the outer axes. I need that both the image on the given axes and the image to be overlaid refer to the same pixels space.
Activity
mdboom commentedon Jul 15, 2013
I think this is by design.
add_artistisn't really intended for data, but for annotations to the data. But we should probably improve the docs on this point.hohlraum commentedon Jul 16, 2013
OK. Sounds like I've been trying to use it incorrectly. I was trying to lazily send artists to
add_artistrather than identifying which ones arepatchesand which arelines. Things work OK when I send theArtistto its specificaddmethod.Clearer docs would be a big plus. I'd try to help, but I'm not clear on the function/intention myself: artists sent to
add_artistare drawn to theAxes, but are excluded fromrelimand hence autoscale? If this is the idea, it seems nicer to:add_artistwhere you could specifyrelim=Falseor
Artistitself.Are there really use cases where people don't want plots to rescale to include annotations?
brianthelion commentedon Nov 26, 2013
I found myself fighting with this issue today. I agree with @hohlraum: I think use-cases where people don't want plots to rescale to include annotations are very much the edge-case.
fredRos commentedon Feb 19, 2014
Seconding @brianthelion, it took me half an hour to find out that axes with an Ellipse added by
add_patch()are rescaled correctly, but not when I useadd_artist(). I recommend it be fixed.tacaswell commentedon Feb 19, 2014
Internally
Axesobjects maintain several lists of ofArtistsobjects that have been added to it based on the type of artist.Currently
relimonly takes into accountself.patchesandself.lines. Changing it so thatrelimwould also take into accountse!f.artistswould be a backwards incompatible change.Please see PR #2822.
tricostume commentedon Apr 11, 2020
Sorry just one question for completeness very related to this topic. How can I then paste an image at a specific position on a given axes (which also contains an image)? I mean I was using OffsetImage in combination with AnnotationBbox but I noticed their reference frames are independent and thus (e.g.) resizing only works for the outer axes. I need that both the image on the given axes and the image to be overlaid refer to the same pixels space.
timhoffm commentedon Apr 11, 2020
Hm, wouldn't it be easier to merge the underlying pixel representations and update with the joint data using
AxesImage.set_data()?