-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Implement conditional autoscaling for Collections using Artist autoscale flag #31274
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
99fee32
e8d3bd3
be151e1
3e6c3c0
9b9a23e
50f4247
424c780
eb2ebe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| import matplotlib.text as mtext | ||
| import matplotlib.ticker as mticker | ||
| import matplotlib.transforms as mtransforms | ||
| import matplotlib.collections as mcollections | ||
|
|
||
| _log = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -1133,6 +1134,11 @@ def _update_transScale(self): | |
| mtransforms.blended_transform_factory( | ||
| self.xaxis.get_transform(), self.yaxis.get_transform())) | ||
|
|
||
| def _update_collection_limits(self, collection): | ||
| offsets = collection.get_offsets() | ||
| if offsets is not None and len(offsets): | ||
| self.update_datalim(offsets) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very wrong indent, I don't know why linting isn't complaining. This method also appears to be inserted into a completely random spot; I'd expect it to be located somewhere that parallels the other |
||
|
|
||
|
timhoffm marked this conversation as resolved.
Outdated
|
||
| def get_position(self, original=False): | ||
| """ | ||
| Return the position of the Axes within the figure as a `.Bbox`. | ||
|
|
@@ -2421,6 +2427,7 @@ def add_collection(self, collection, autolim=True): | |
| self._request_autoscale_view() | ||
|
|
||
| self.stale = True | ||
| collection._set_in_autoscale(autolim) | ||
| return collection | ||
|
|
||
| def add_image(self, image): | ||
|
|
@@ -2649,6 +2656,8 @@ def relim(self, visible_only=False): | |
| self._update_patch_limits(artist) | ||
| elif isinstance(artist, mimage.AxesImage): | ||
| self._update_image_limits(artist) | ||
| elif isinstance(artist, mcollections.Collection): | ||
| self._update_collection_limits(artist) | ||
|
|
||
| def update_datalim(self, xys, updatex=True, updatey=True): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10189,3 +10189,27 @@ def test_errorbar_uses_rcparams(): | |
| assert_allclose([cap.get_markeredgewidth() for cap in caplines], 2.5) | ||
| for barcol in barlinecols: | ||
| assert_allclose(barcol.get_linewidths(), 1.75) | ||
|
|
||
|
|
||
| def test_relim_updates_scatter_offsets(): | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary imports. |
||
| fig, ax = plt.subplots() | ||
|
|
||
| xs = np.linspace(0, 10, 100) | ||
| ys = np.sin(xs) | ||
| scatter = ax.scatter(xs, ys) | ||
|
|
||
| # Shift scatter upward | ||
| new_ys = np.sin(xs) + 5 | ||
| scatter.set_offsets(np.column_stack((xs, new_ys))) | ||
|
|
||
| ax.relim() | ||
| ax.autoscale_view() | ||
|
|
||
| ymin, ymax = ax.get_ylim() | ||
|
|
||
| # New limits should reflect shifted data | ||
| assert ymin > 3 | ||
| assert ymax > 5 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collectionsis already imported above.