46
46
from numpy .linalg import inv
47
47
48
48
from 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
51
50
from .path import Path
52
51
53
52
DEBUG = False
@@ -868,8 +867,8 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
868
867
if path .vertices .size == 0 :
869
868
return
870
869
871
- points , minpos , changed = update_path_extents (
872
- path , None , self . _points , self . _minpos , ignore )
870
+ points , minpos , changed = self . _calc_extents_from_path ( path , ignore ,
871
+ updatex , updatey )
873
872
874
873
if changed :
875
874
self .invalidate ()
@@ -880,6 +879,60 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
880
879
self ._points [:, 1 ] = points [:, 1 ]
881
880
self ._minpos [1 ] = minpos [1 ]
882
881
882
+ def _calc_extents_from_path (self , path , ignore , updatex = True , updatey = True ):
883
+ """
884
+ Calculate the new bounds and minimum positive values for a `Bbox` from
885
+ the path.
886
+
887
+ Parameters
888
+ ----------
889
+ path : `~matplotlib.path.Path`
890
+ ignore : bool
891
+ - When ``True``, ignore the existing bounds of the `Bbox`.
892
+ - When ``False``, include the existing bounds of the `Bbox`.
893
+ updatex : bool
894
+ When ``True``, update the x-values.
895
+ updatey : bool
896
+ When ``True``, update the y-values.
897
+
898
+ Returns
899
+ -------
900
+ points : (2, 2) array
901
+ minpos : (2,) array
902
+ changed : bool
903
+ """
904
+ if ignore :
905
+ points = np .array ([[np .inf , np .inf ], [- np .inf , - np .inf ]])
906
+ minpos = np .array ([np .inf , np .inf ])
907
+ else :
908
+ points = self ._points .copy ()
909
+ minpos = self ._minpos .copy ()
910
+
911
+ if updatex and updatey :
912
+ where = (np .isfinite (path .vertices [..., 0 ])
913
+ & np .isfinite (path .vertices [..., 1 ]))
914
+ elif updatex :
915
+ where = np .isfinite (path .vertices [..., 0 ])
916
+ elif updatey :
917
+ where = np .isfinite (path .vertices [..., 1 ])
918
+ else :
919
+ return points , minpos , False
920
+
921
+ if updatex :
922
+ x = path .vertices [..., 0 ][where ]
923
+ points [0 , 0 ] = min (points [0 , 0 ], np .min (x , initial = np .inf ))
924
+ points [1 , 0 ] = max (points [1 , 0 ], np .max (x , initial = - np .inf ))
925
+ minpos [0 ] = min (minpos [0 ], np .min (x [x > 0 ], initial = np .inf ))
926
+ if updatey :
927
+ y = path .vertices [..., 1 ][where ]
928
+ points [0 , 1 ] = min (points [0 , 1 ], np .min (y , initial = np .inf ))
929
+ points [1 , 1 ] = max (points [1 , 1 ], np .max (y , initial = - np .inf ))
930
+ minpos [1 ] = min (minpos [1 ], np .min (y [y > 0 ], initial = np .inf ))
931
+
932
+ changed = np .any (points != self ._points ) or np .any (minpos != self ._minpos )
933
+
934
+ return points , minpos , changed
935
+
883
936
def update_from_data_x (self , x , ignore = None ):
884
937
"""
885
938
Update the x-bounds of the `Bbox` based on the passed in data. After
0 commit comments