8000 [ENH]: allow scatter plots to preserve data limits. · Issue #24416 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[ENH]: allow scatter plots to preserve data limits. #24416
Open
@juseg

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.

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

      0