@@ -717,6 +717,8 @@ class _WedgeBbox(mtransforms.Bbox):
717
717
"""
718
718
Transform (theta, r) wedge Bbox into Axes bounding box.
719
719
720
+ Additionally, this class will update the Axes patch, if set by `_set_wedge`.
721
+
720
722
Parameters
721
723
----------
722
724
center : (float, float)
@@ -731,6 +733,7 @@ def __init__(self, center, viewLim, originLim, **kwargs):
731
733
self ._center = center
732
734
self ._viewLim = viewLim
733
735
self ._originLim = originLim
736
+ self ._wedge = None
734
737
self .set_children (viewLim , originLim )
735
738
736
739
__str__ = mtransforms ._make_str_method ("_center" , "_viewLim" , "_originLim" )
@@ -753,10 +756,22 @@ def get_points(self):
753
756
width = min (points [1 , 1 ] - points [0 , 1 ], 0.5 )
754
757
755
758
# Generate bounding box for wedge.
756
- wedge = mpatches .Wedge (self ._center , points [1 , 1 ],
757
- points [0 , 0 ], points [1 , 0 ],
758
- width = width )
759
- self .update_from_path (wedge .get_path ())
759
+ if self ._wedge is None :
760
+ # A PolarAxes subclass may not generate a Wedge as Axes patch and call
761
+ # _WedgeBbox._set_wedge, so use a temporary instance to calculate the
762
+ # bounds instead.
763
+ wedge = mpatches .Wedge (self ._center , points [1 , 1 ],
764
+ points [0 , 0 ], points [1 , 0 ],
765
+ width = width )
766
+ else :
767
+ # Update the owning Axes' patch.
768
+ wedge = self ._wedge
769
+ wedge .set_center (self ._center )
770
+ wedge .set_theta1 (points [0 , 0 ])
771
+ wedge .set_theta2 (points [1 , 0 ])
772
+ wedge .set_radius (points [1 , 1 ])
773
+ wedge .set_width (width )
774
+ self .update_from_path (wedge .get_path (), ignore = True )
760
775
761
776
# Ensure equal aspect ratio.
762
777
w , h = self ._points [1 ] - self ._points [0 ]
@@ -768,6 +783,11 @@ def get_points(self):
768
783
769
784
return self ._points
770
785
786
+ def _set_wedge (self , wedge ):
787
+ """Set the wedge patch to update when the transform changes."""
788
+ _api .check_isinstance (mpatches .Wedge , wedge = wedge )
789
+ self ._wedge = wedge
790
+
771
791
772
792
class PolarAxes (Axes ):
773
793
"""
@@ -958,31 +978,15 @@ def get_yaxis_text2_transform(self, pad):
958
978
959
979
def draw (self , renderer ):
960
980
self ._unstale_viewLim ()
961
- thetamin , thetamax = np .rad2deg (self ._realViewLim .intervalx )
962
- if thetamin > thetamax :
963
- thetamin , thetamax = thetamax , thetamin
964
- rmin , rmax = ((self ._realViewLim .intervaly - self .get_rorigin ()) *
965
- self .get_rsign ())
981
+ self .axesLim .get_points () # Unstale bbox and Axes patch.
966
982
if isinstance (self .patch , mpatches .Wedge ):
967
983
# Backwards-compatibility: Any subclassed Axes might override the
968
984
# patch to not be the Wedge that PolarAxes uses.
969
- center = self .transWedge .transform ((0.5 , 0.5 ))
970
- self .patch .set_center (center )
971
- self .patch .set_theta1 (thetamin )
972
- self .patch .set_theta2 (thetamax )
973
-
974
- edge , _ = self .transWedge .transform ((1 , 0 ))
975
- radius = edge - center [0 ]
976
- width = min (radius * (rmax - rmin ) / rmax , radius )
977
- self .patch .set_radius (radius )
978
- self .patch .set_width (width )
979
-
980
- inner_width = radius - width
981
985
inner = self .spines .get ('inner' , None )
982
986
if inner :
983
- inner .set_visible (inner_width != 0.0 )
987
+ inner .set_visible (self . patch . r != self . patch . width )
984
988
985
- visible = not _is_full_circle_deg ( thetamin , thetamax )
989
+ visible = not _is_full_circle_rad ( * self . _realViewLim . intervalx )
986
990
# For backwards compatibility, any subclassed Axes might override the
987
991
# spines to not include start/end that PolarAxes uses.
988
992
start = self .spines .get ('start' , None )
@@ -1002,8 +1006,20 @@ def draw(self, renderer):
1002
1006
1003
1007
super ().draw (renderer )
1004
1008
1009
+ def _wedge_get_patch_transform (self ):
1010
+ # See _gen_axes_patch for the use of this function. It's not a lambda or nested
1011
+ # function to not break pickling.
1012
+ return self .transWedge
1013
+
1005
1014
def _gen_axes_patch (self ):
1006
- return mpatches .Wedge ((0.5 , 0.5 ), 0.5 , 0.0 , 360.0 )
1015
+ wedge = mpatches .Wedge ((0.5 , 0.5 ), 0.5 , 0.0 , 360.0 )
1016
+ self .axesLim ._set_wedge (wedge )
1017
+ # The caller of this function will set the wedge's transform directly to
1018
+ # `self.transAxes`, but `self.axesLim` will update to a pre-`self.transWedge`
1019
+ # coordinate space, so override the patch transform (which is otherwise always
1020
+ # an identity transform) to get the wedge in the right coordinate space.
1021
+ wedge .get_patch_transform = self ._wedge_get_patch_transform
1022
+ return wedge
1007
1023
1008
1024
def _gen_axes_spines (self ):
1009
1025
spines = {
0 commit comments