@@ -2410,26 +2410,7 @@ def add_collection(self, collection, autolim=True):
24102410 # Make sure viewLim is not stale (mostly to match
24112411 # pre-lazy-autoscale behavior, which is not really better).
24122412 self ._unstale_viewLim ()
2413- datalim = collection .get_datalim (self .transData )
2414- points = datalim .get_points ()
2415- if not np .isinf (datalim .minpos ).all ():
2416- # By definition, if minpos (minimum positive value) is set
2417- # (i.e., non-inf), then min(points) <= minpos <= max(points),
2418- # and minpos would be superfluous. However, we add minpos to
2419- # the call so that self.dataLim will update its own minpos.
2420- # This ensures that log scales see the correct minimum.
2421- points = np .concatenate ([points , [datalim .minpos ]])
2422- # only update the dataLim for x/y if the collection uses transData
2423- # in this direction.
2424- x_is_data , y_is_data = (collection .get_transform ()
2425- .contains_branch_separately (self .transData ))
2426- ox_is_data , oy_is_data = (collection .get_offset_transform ()
2427- .contains_branch_separately (self .transData ))
2428- self .update_datalim (
2429- points ,
2430- updatex = x_is_data or ox_is_data ,
2431- updatey = y_is_data or oy_is_data ,
2432- )
2413+ self ._update_collection_limits (collection )
24332414 if autolim != "_datalim_only" :
24342415 self ._request_autoscale_view ()
24352416 # Mark collection as participating in relim() only when autolim
@@ -2602,6 +2583,29 @@ def _update_patch_limits(self, patch):
26022583 xys = trf_to_data .transform (vertices )
26032584 self .update_datalim (xys , updatex = updatex , updatey = updatey )
26042585
2586+ def _update_collection_limits (self , collection ):
2587+ """Update the data limits for the given collection."""
2588+ datalim = collection .get_datalim (self .transData )
2589+ points = datalim .get_points ()
2590+ if not np .isinf (datalim .minpos ).all ():
2591+ # By definition, if minpos (minimum positive value) is set
2592+ # (i.e., non-inf), then min(points) <= minpos <= max(points),
2593+ # and minpos would be superfluous. However, we add minpos to
2594+ # the call so that self.dataLim will update its own minpos.
2595+ # This ensures that log scales see the correct minimum.
2596+ points = np .concatenate ([points , [datalim .minpos ]])
2597+ # only update the dataLim for x/y if the collection uses transData
2598+ # in this direction.
2599+ x_is_data , y_is_data = (collection .get_transform ()
2600+ .contains_branch_separately (self .transData ))
2601+ ox_is_data , oy_is_data = (collection .get_offset_transform ()
2602+ .contains_branch_separately (self .transData ))
2603+ self .update_datalim (
2604+ points ,
2605+ updatex = x_is_data or ox_is_data ,
2606+ updatey = y_is_data or oy_is_data ,
2607+ )
2608+
26052609 def add_table (self , tab ):
26062610 """
26072611 Add a `.Table` to the Axes; return the table.
@@ -2662,27 +2666,7 @@ def relim(self, visible_only=False):
26622666 elif isinstance (artist , mimage .AxesImage ):
26632667 self ._update_image_limits (artist )
26642668 elif isinstance (artist , mcoll .Collection ):
2665- datalim = artist .get_datalim (self .transData )
2666- points = datalim .get_points ()
2667- if not np .isinf (datalim .minpos ).all ():
2668- # As in add_collection: include minpos so that
2669- # self.dataLim updates its own minpos, which ensures
2670- # log scales see the correct minimum.
2671- points = np .concatenate ([points ,
2672- [datalim .minpos ]])
2673- # Only update dataLim for x/y if the collection uses
2674- # transData in that direction.
2675- x_is_data , y_is_data = (
2676- artist .get_transform ()
2677- .contains_branch_separately (self .transData ))
2678- ox_is_data , oy_is_data = (
2679- artist .get_offset_transform ()
2680- .contains_branch_separately (self .transData ))
2681- self .update_datalim (
2682- points ,
2683- updatex = x_is_data or ox_is_data ,
2684- updatey = y_is_data or oy_is_data ,
2685- )
2669+ self ._update_collection_limits (artist )
26862670
26872671 def update_datalim (self , xys , updatex = True , updatey = True ):
26882672 """
0 commit comments