Skip to content

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

Closed

Description

@hohlraum

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

Activity

  1. mdboom commented on Jul 15, 2013

    @mdboom
    Member

    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.

  2. hohlraum commented on Jul 16, 2013

    @hohlraum
    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?

  3. brianthelion commented on Nov 26, 2013

    @brianthelion

    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.

  4. fredRos commented on Feb 19, 2014

    @fredRos

    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.

  5. added this to the v1.4.x milestone on Feb 19, 2014
  6. tacaswell commented on Feb 19, 2014

    @tacaswell
    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.

  7. tricostume commented on Apr 11, 2020

    @tricostume

    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.

  8. timhoffm commented on Apr 11, 2020

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions