@@ -3154,13 +3154,13 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
31543154self .add_container (stem_container )
31553155return stem_container
31563156
3157- @_api .make_keyword_only ("3.9 " ,"explode " )
3157+ @_api .rename_parameter ("3.11 " ,"pctdistance" , "autodistance " )
31583158@_preprocess_data (replace_names = ["x" ,"explode" ,"labels" ,"colors" ])
3159- def pie (self ,x ,explode = None ,labels = None ,colors = None ,
3160- autopct = None ,pctdistance = 0.6 ,shadow = False ,labeldistance = 1.1 ,
3159+ def pie (self ,x ,* , explode = None ,labels = None ,colors = None , absolutefmt = None ,
3160+ autopct = None ,autodistance = 0.6 ,shadow = False ,labeldistance = 1.1 ,
31613161startangle = 0 ,radius = 1 ,counterclock = True ,
31623162wedgeprops = None ,textprops = None ,center = (0 ,0 ),
3163- frame = False ,rotatelabels = False ,* , normalize = True ,hatch = None ):
3163+ frame = False ,rotatelabels = False ,normalize = True ,hatch = None ):
31643164"""
31653165 Plot a pie chart.
31663166
@@ -3193,18 +3193,38 @@ def pie(self, x, explode=None, labels=None, colors=None,
31933193
31943194 .. versionadded:: 3.7
31953195
3196+ absolutefmt : None or str or callable, default: None
3197+ If not *None*, *absolutefmt* is a string or function used to label
3198+ the wedges with their original numeric values. The label will be
3199+ placed according to *autodistance*. If *absolutefmt* is a format
3200+ string, the label will be ``fmt % number``. If *absolutefmt* is a
3201+ function, then it will be called. Cannot be used at the same time
3202+ as *autopct*.
3203+
3204+ .. versionadded:: 3.11
3205+
31963206 autopct : None or str or callable, default: None
31973207 If not *None*, *autopct* is a string or function used to label the
3198- wedges with their numeric value. The label will be placed inside
3199- the wedge. If *autopct* is a format string, the label will be
3200- ``fmt % pct``. If *autopct* is a function, then it will be called.
3208+ wedges with their percentage values. The label will be placed
3209+ according to *autodistance*. If *autopct* is a format string, the
3210+ label will be ``fmt % pct``. If *autopct* is a function, then it
3211+ will be called. Cannot be used at the same time as *absolutefmt*.
3212+
3213+ autodistance : float, default: 0.6
3214+ The relative distance along the radius at which the text
3215+ generated by *absolutefmt* or *autopct* is drawn. To draw the text
3216+ outside the pie, set *autodistance* > 1. This parameter is ignored
3217+ if both *absolutefmt* and *autopct* are ``None``.
32013218
32023219 pctdistance : float, default: 0.6
32033220 The relative distance along the radius at which the text
32043221 generated by *autopct* is drawn. To draw the text outside the pie,
32053222 set *pctdistance* > 1. This parameter is ignored if *autopct* is
32063223 ``None``.
32073224
3225+ .. deprecated:: 3.11
3226+ Use *autodistance* instead.
3227+
32083228 labeldistance : float or None, default: 1.1
32093229 The relative distance along the radius at which the labels are
32103230 drawn. To draw the labels inside the pie, set *labeldistance* < 1.
@@ -3275,9 +3295,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
32753295 The Axes aspect ratio can be controlled with `.Axes.set_aspect`.
32763296 """
32773297self .set_aspect ('equal' )
3278- # The use of float32 is "historical", but can't be changed without
3279- # regenerating the test baselines.
3280- x = np .asarray (x ,np .float32 )
3298+ x = np .asarray (x )
32813299if x .ndim > 1 :
32823300raise ValueError ("x must be 1D" )
32833301
@@ -3287,9 +3305,11 @@ def pie(self, x, explode=None, labels=None, colors=None,
32873305sx = x .sum ()
32883306
32893307if normalize :
3290- x = x / sx
3308+ fracs = x / sx
32913309elif sx > 1 :
32923310raise ValueError ('Cannot plot an unnormalized pie with sum(x) > 1' )
3311+ else :
3312+ fracs = x
32933313if labels is None :
32943314labels = ['' ]* len (x )
32953315if explode is None :
@@ -3324,7 +3344,7 @@ def get_next_color():
33243344slices = []
33253345autotexts = []
33263346
3327- for frac ,label ,expl in zip (x ,labels ,explode ):
3347+ for n , frac ,label ,expl in zip (x , fracs ,labels ,explode ):
33283348x ,y = center
33293349theta2 = (theta1 + frac )if counterclock else (theta1 - frac )
33303350thetam = 2 * np .pi * 0.5 * (theta1 + theta2 )
@@ -3369,15 +3389,33 @@ def get_next_color():
33693389texts .append (t )
33703390
33713391if autopct is not None :
3372- xt = x + pctdistance * radius * math . cos ( thetam )
3373- yt = y + pctdistance * radius * math . sin ( thetam )
3392+ if absolutefmt is not None :
3393+ raise ValueError ( 'Only one of autopct and absolutefmt may be used.' )
33743394if isinstance (autopct ,str ):
33753395s = autopct % (100. * frac )
33763396elif callable (autopct ):
33773397s = autopct (100. * frac )
33783398else :
33793399raise TypeError (
33803400'autopct must be callable or a format string' )
3401+ autolabels = True
3402+
3403+ elif absolutefmt is not None :
3404+ if isinstance (absolutefmt ,str ):
3405+ s = absolutefmt % n
3406+ elif callable (absolutefmt ):
3407+ s = absolutefmt (n )
3408+ else :
3409+ raise TypeError (
3410+ 'absolutefmt must be callable or a format string' )
3411+ autolabels = True
3412+
3413+ else :
3414+ autolabels = False
3415+
3416+ if autolabels :
3417+ xt = x + autodistance * radius * math .cos (thetam )
3418+ yt = y + autodistance * radius * math .sin (thetam )
33813419if mpl ._val_or_rc (textprops .get ("usetex" ),"text.usetex" ):
33823420# escape % (i.e. \%) if it is not already escaped
33833421s = re .sub (r"([^\\])%" ,r"\1\\%" ,s )
@@ -3397,7 +3435,7 @@ def get_next_color():
33973435xlim = (- 1.25 + center [0 ],1.25 + center [0 ]),
33983436ylim = (- 1.25 + center [1 ],1.25 + center [1 ]))
33993437
3400- if autopct is None :
3438+ if not autotexts :
34013439return slices ,texts
34023440else :
34033441return slices ,texts ,autotexts