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

Autoscale does not work for artists added with Axes.add_artist #2202

Closed
hohlraum opened this issue Jul 4, 2013 · 7 comments · Fixed by #3108
Closed

Autoscale does not work for artists added with Axes.add_artist #2202

hohlraum opened this issue Jul 4, 2013 · 7 comments · Fixed by #3108

Comments

@hohlraum
Copy link

hohlraum commented Jul 4, 2013

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 this

ax.relim()  # not strictly necessary
ax.autoscale(True)
plt.show()
@mdboom
Copy link
Member

mdboom commented Jul 15, 2013

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.

@hohlraum
Copy link
Author

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?

@brianthelion
Copy link

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

fredRos commented Feb 19, 2014

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.

@tacaswell
Copy link
Member

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.

Please see PR #2822.

@tricostume
Copy link

tricostume commented 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
Copy link
Member

Hm, wouldn't it be easier to merge the underlying pixel representations and update with the joint data using AxesImage.set_data()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants