4646from numpy .linalg import inv
4747
4848from matplotlib import _api
49- from matplotlib ._path import (
50- affine_transform , count_bboxes_overlapping_bbox , update_path_extents )
49+ from matplotlib ._path import affine_transform , count_bboxes_overlapping_bbox
5150from .path import Path
5251
5352DEBUG = False
@@ -871,8 +870,8 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
871870 if path .vertices .size == 0 :
872871 return
873872
874- points , minpos , changed = update_path_extents (
875- path , None , self . _points , self . _minpos , ignore )
873+ points , minpos , changed = self . _calc_extents_from_path ( path , ignore ,
874+ updatex , updatey )
876875
877876 if changed :
878877 self .invalidate ()
@@ -883,6 +882,56 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
883882 self ._points [:, 1 ] = points [:, 1 ]
884883 self ._minpos [1 ] = minpos [1 ]
885884
885+ def _calc_extents_from_path (self , path , ignore , updatex = True , updatey = True ):
886+ """
887+ Calculate the new bounds and minimum positive values for a `Bbox` from
888+ the path.
889+
890+ Parameters
891+ ----------
892+ path : `~matplotlib.path.Path`
893+ ignore : bool
894+ - When ``True``, ignore the existing bounds of the `Bbox`.
895+ - When ``False``, include the existing bounds of the `Bbox`.
896+ updatex : bool
897+ When ``True``, update the x-values.
898+ updatey : bool
899+ When ``True``, update the y-values.
900+
901+ Returns
902+ -------
903+ points : (2, 2) array
904+ minpos : (2,) array
905+ changed : bool
906+ """
907+ if ignore :
908+ points = np .array ([[np .inf , np .inf ], [- np .inf , - np .inf ]])
909+ minpos = np .array ([np .inf , np .inf ])
910+ else :
911+ points = self ._points .copy ()
912+ minpos = self ._minpos .copy ()
913+
914+ if not (updatex or updatey ):
915+ return points , minpos , False
916+
917+ valid_points = (np .isfinite (path .vertices [..., 0 ])
918+ & np .isfinite (path .vertices [..., 1 ]))
919+
920+ if updatex :
921+ x = path .vertices [..., 0 ][valid_points ]
922+ points [0 , 0 ] = min (points [0 , 0 ], np .min (x , initial = np .inf ))
923+ points [1 , 0 ] = max (points [1 , 0 ], np .max (x , initial = - np .inf ))
924+ minpos [0 ] = min (minpos [0 ], np .min (x [x > 0 ], initial = np .inf ))
925+ if updatey :
926+ y = path .vertices [..., 1 ][valid_points ]
927+ points [0 , 1 ] = min (points [0 , 1 ], np .min (y , initial = np .inf ))
928+ points [1 , 1 ] = max (points [1 , 1 ], np .max (y , initial = - np .inf ))
929+ minpos [1 ] = min (minpos [1 ], np .min (y [y > 0 ], initial = np .inf ))
930+
931+ changed = np .any (points != self ._points ) or np .any (minpos != self ._minpos )
932+
933+ return points , minpos , changed
934+
886935 def update_from_data_x (self , x , ignore = None ):
887936 """
888937 Update the x-bounds of the `Bbox` based on the passed in data. After
@@ -899,8 +948,9 @@ def update_from_data_x(self, x, ignore=None):
899948 - When ``None``, use the last value passed to :meth:`ignore`.
900949 """
901950 x = np .ravel (x )
902- self .update_from_data_xy (np .column_stack ([x , np .ones (x .size )]),
903- ignore = ignore , updatey = False )
951+ # The y-component in np.array([x, *y*]).T is not used. We simply pass
952+ # x again to not spend extra time on creating an array of unused data
953+ self .update_from_data_xy (np .array ([x , x ]).T , ignore = ignore , updatey = False )
904954
905955 def update_from_data_y (self , y , ignore = None ):
906956 """
@@ -918,8 +968,9 @@ def update_from_data_y(self, y, ignore=None):
918968 - When ``None``, use the last value passed to :meth:`ignore`.
919969 """
920970 y = np .ravel (y )
921- self .update_from_data_xy (np .column_stack ([np .ones (y .size ), y ]),
922- ignore = ignore , updatex = False )
971+ # The x-component in np.array([*x*, y]).T is not used. We simply pass
972+ # y again to not spend extra time on creating an array of unused data
973+ self .update_from_data_xy (np .array ([y , y ]).T , ignore = ignore , updatex = False )
923974
924975 def update_from_data_xy (self , xy , ignore = None , updatex = True , updatey = True ):
925976 """
0 commit comments