@@ -3514,13 +3514,13 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
35143514self .add_container (stem_container )
35153515return stem_container
35163516
3517- @_api . make_keyword_only ( "3.10 " ,"explode" )
3518- @ _preprocess_data ( replace_names = [ "x" , "explode" , "labels" , "colors " ])
3519- def pie (self ,x ,explode = None ,labels = None ,colors = None ,
3520- autopct = None ,pctdistance = 0.6 ,shadow = False , labeldistance = 1.1 ,
3521- startangle = 0 ,radius = 1 ,counterclock = True ,
3522- wedgeprops = None ,textprops = None ,center = (0 ,0 ),
3523- frame = False , rotatelabels = False , * ,normalize = True ,hatch = None ):
3517+ @_preprocess_data ( replace_names = [ "x " ,"explode" , "labels" , "colors" ,
3518+ "wedge_labels " ])
3519+ def pie (self ,x ,* , explode = None ,labels = None ,colors = None , wedge_labels = None ,
3520+ wedge_label_distance = 0.6 , autopct = None ,pctdistance = 0.6 ,shadow = False ,
3521+ labeldistance = False , startangle = 0 ,radius = 1 ,counterclock = True ,
3522+ wedgeprops = None ,textprops = None ,center = (0 ,0 ),frame = False ,
3523+ rotatelabels = False ,normalize = True ,hatch = None ):
35243524"""
35253525 Plot a pie chart.
35263526
@@ -3540,7 +3540,13 @@ def pie(self, x, explode=None, labels=None, colors=None,
35403540 of the radius with which to offset each wedge.
35413541
35423542 labels : list, default: None
3543- A sequence of strings providing the labels for each wedge
3543+ A sequence of strings providing the legend labels for each wedge.
3544+
3545+ .. deprecated:: 3.12
3546+ In future these labels will not appear on the wedges but only
3547+ be made available for the legend (see *labeldistance* below).
3548+ To label the wedges directly, use *wedge_labels* or the
3549+ `pie_label` method.
35443550
35453551 colors : :mpltype:`color` or list of :mpltype:`color`, default: None
35463552 A sequence of colors through which the pie chart will cycle. If
@@ -3553,12 +3559,34 @@ def pie(self, x, explode=None, labels=None, colors=None,
35533559
35543560 .. versionadded:: 3.7
35553561
3562+ wedge_labels : str or list of str, optional
3563+ A sequence of strings providing the labels for each wedge, or a format
3564+ string with ``absval`` and/or ``frac`` placeholders. For example, to label
3565+ each wedge with its value and the percentage in brackets::
3566+
3567+ wedge_labels="{absval:d} ({frac:.0%})"
3568+
3569+ For more control or to add multiple sets of labels, use `pie_label`.
3570+
3571+ .. versionadded:: 3.12
3572+
3573+ wedge_label_distance : float, default: 0.6
3574+ The radial position of the wedge labels, relative to the pie radius.
3575+ Values > 1 are outside the wedge and values < 1 are inside the wedge.
3576+
3577+ .. versionadded:: 3.12
3578+
35563579 autopct : None or str or callable, default: None
35573580 If not *None*, *autopct* is a string or function used to label the
35583581 wedges with their numeric value. The label will be placed inside
35593582 the wedge. If *autopct* is a format string, the label will be
35603583 ``fmt % pct``. If *autopct* is a function, then it will be called.
35613584
3585+ .. admonition:: Discouraged
3586+
3587+ Consider using the *wedge_labels* parameter or `pie_label`
3588+ method instead.
3589+
35623590 pctdistance : float, default: 0.6
35633591 The relative distance along the radius at which the text
35643592 generated by *autopct* is drawn. To draw the text outside the pie,
@@ -3571,6 +3599,11 @@ def pie(self, x, explode=None, labels=None, colors=None,
35713599 If set to ``None``, labels are not drawn but are still stored for
35723600 use in `.legend`.
35733601
3602+ .. deprecated:: 3.12
3603+ From v3.14 *labeldistance* will default to ``None`` and will
3604+ later be removed altogether. Use *wedge_labels* and
3605+ *wedge_label_distance* or the `pie_label` method instead.
3606+
35743607 shadow : bool or dict, default: False
35753608 If bool, whether to draw a shadow beneath the pie. If dict, draw a shadow
35763609 passing the properties in the dict to `.Shadow`.
@@ -3654,6 +3687,17 @@ def pie(self, x, explode=None, labels=None, colors=None,
36543687fracs = x
36553688if labels is None :
36563689labels = ['' ]* len (x )
3690+ elif labeldistance is False :
3691+ # NB: when the labeldistance default changes, both labeldistance and
3692+ # rotatelabels should be deprecated for removal.
3693+ msg = ("From %(removal)s labeldistance will default to None, so that the "
3694+ "strings provided in the labels parameter are only available for "
3695+ "the legend. Later labeldistance will be removed completely. To "
3696+ "preserve existing behavior for now, pass labeldistance=1.1. "
3697+ "Consider using the wedge_labels parameter or the pie_label method "
3698+ "instead of the labels parameter." )
3699+ _api .warn_deprecated ("3.12" ,message = msg )
3700+ labeldistance = 1.1
36573701if explode is None :
36583702explode = [0 ]* len (x )
36593703if len (x )!= len (labels ):
@@ -3711,11 +3755,16 @@ def get_next_color():
37113755
37123756pc = PieContainer (slices ,x ,normalize )
37133757
3714- if labeldistance is None :
3758+ if wedge_labels is not None :
3759+ self .pie_label (pc ,wedge_labels ,distance = wedge_label_distance ,
3760+ textprops = textprops )
3761+
3762+ elif labeldistance is None :
37153763# Insert an empty list of texts for backwards compatibility of the
37163764# return value.
37173765pc .add_texts ([])
3718- else :
3766+
3767+ if labeldistance is not None :
37193768# Add labels to the wedges.
37203769labels_textprops = {
37213770'fontsize' :mpl .rcParams ['xtick.labelsize' ],