FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix relim() ignoring scatter PathCollection offsets by Archiljain · Pull Request #31128 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 9 additions & 0 deletions lib/matplotlib/axes/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -2415,6 +2416,12 @@ def _update_image_limits(self, image):
xmin, xmax, ymin, ymax = image.get_extent()
self.axes.update_datalim(((xmin, ymin), (xmax, ymax)))

def _update_collection_limits(self, collection):
offsets = collection.get_offsets()
if offsets is not None and len(offsets):
self.update_datalim(offsets)


def add_line(self, line):
"""
Add a `.Line2D` to the Axes; return the line.
Expand Down Expand Up @@ -2605,6 +2612,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):
"""
Expand Down
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10159,3 +10159,27 @@ def test_animated_artists_not_drawn_by_default():

mocked_im_draw.assert_not_called()
mocked_ln_draw.assert_not_called()


def test_relim_updates_scatter_offsets():
import numpy as np
import matplotlib.pyplot as plt

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
Loading

Back | FazBrowse Home | New Git URL