File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929import matplotlib .text as mtext
3030import matplotlib .ticker as mticker
3131import matplotlib .transforms as mtransforms
32+ import matplotlib .collections as mcollections
3233
3334_log = logging .getLogger (__name__ )
3435
@@ -2605,6 +2606,10 @@ def relim(self, visible_only=False):
26052606 self ._update_patch_limits (artist )
26062607 elif isinstance (artist , mimage .AxesImage ):
26072608 self ._update_image_limits (artist )
2609+ elif isinstance (artist , mcollections .Collection ):
2610+ offsets = artist .get_offsets ()
2611+ if offsets is not None and len (offsets ):
2612+ self .update_datalim (offsets )
26082613
26092614 def update_datalim (self , xys , updatex = True , updatey = True ):
26102615 """
Original file line number Diff line number Diff line change @@ -10159,3 +10159,26 @@ def test_animated_artists_not_drawn_by_default():
1015910159
1016010160 mocked_im_draw .assert_not_called ()
1016110161 mocked_ln_draw .assert_not_called ()
10162+
10163+ def test_relim_updates_scatter_offsets ():
10164+ import numpy as np
10165+ import matplotlib .pyplot as plt
10166+
10167+ fig , ax = plt .subplots ()
10168+
10169+ xs = np .linspace (0 , 10 , 100 )
10170+ ys = np .sin (xs )
10171+ scatter = ax .scatter (xs , ys )
10172+
10173+ # Shift scatter upward
10174+ new_ys = np .sin (xs ) + 5
10175+ scatter .set_offsets (np .column_stack ((xs , new_ys )))
10176+
10177+ ax .relim ()
10178+ ax .autoscale_view ()
10179+
10180+ ymin , ymax = ax .get_ylim ()
10181+
10182+ # New limits should reflect shifted data
10183+ assert ymin > 3
10184+ assert ymax > 5
You can’t perform that action at this time.
0 commit comments