Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem
I would like to plot scatter points as contextual data while preserving the current axes data limits. Something like this can be achieved withAxes.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, whichAxes.scatter
uses in the background.
Context: this feature will allow GeoPandas to consistently plot line, polygon (usingadd_collection()
) and point data (usingscatter()
) as contextual data not affecting axes limits (seegeopandas/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 thatadd_collection
has anautolim
keyword that defaults toTrue
. As opposed to completely disabling auto-scaling, settingautolim=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 theautolim
keyword argument toAxes.scatter
and pass it toadd_collection
here:
matplotlib/lib/matplotlib/axes/_axes.py
Lines 4680 to 4681 in9d8fde2
self.add_collection(collection) | |
self._request_autoscale_view() |
This would allow something like:
ax.scatter(x_subject,y_subject)# default to autolim=True, update limitsax.scatter(x_context,y_context,autolim=False)# don't update limitsax.plot(something_else)# update limits disregarding {x,y}_context
I am happy to open a PR if this makes sense.