Skip to content

[ENH]: allow scatter plots to preserve data limits. #24416

Open

Description

@juseg

Problem

I would like to plot scatter points as contextual data while preserving the current axes data limits. Something like this can be achieved with Axes.set_autoscale(False), but I would like to keep auto-scaling on, and disable it for a particular feature. As far as I understand this is how collections work, which Axes.scatter uses in the background.

Context: this feature will allow GeoPandas to consistently plot line, polygon (using add_collection()) and point data (using scatter()) as contextual data not affecting axes limits (see geopandas/geopandas#2602). Down the line it will benefit a small library I am developing (hyoga), to plot gridded data with xarray, and geographic data for context with geopandas.

Proposed solution

I noticed that add_collection has an autolim keyword that defaults to True. As opposed to completely disabling auto-scaling, setting autolim=False simply skips updating the axes data limits for this particular collection, meaning auto-scaling stays on, but ignores it (if I read this correctly). I propose to propagate the autolim keyword argument to Axes.scatter and pass it to add_collection here:

self.add_collection(collection)
self._request_autoscale_view()

This would allow something like:

ax.scatter(x_subject, y_subject)  # default to autolim=True, update limits
ax.scatter(x_context, y_context, autolim=False)  # don't update limits
ax.plot(something_else)  # update limits disregarding {x,y}_context

I am happy to open a PR if this makes sense.

Activity

  1. timhoffm commented on Nov 11, 2022

    @timhoffm
    Member

    Related, but stalled: #15595.

  2. rcomer commented on Dec 7, 2024

    @rcomer
    Member

    I just stumbled across this. Is there a reason not to expose autolim in scatter? I do not have a use case, but it seems like it would be a simple change that helps geopandas.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions