@@ -3514,13 +3514,13 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
35143514 self .add_container (stem_container )
35153515 return 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 place labels on the wedges, 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,35 @@ 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+ instead.
3571+
3572+ .. versionadded:: 3.12
3573+
3574+ wedge_label_distance : float, default: 0.6
3575+ The radial position of the wedge labels, relative to the pie radius.
3576+ Values > 1 are outside the wedge and values < 1 are inside the wedge.
3577+
3578+ .. versionadded:: 3.12
3579+
35563580 autopct : None or str or callable, default: None
35573581 If not *None*, *autopct* is a string or function used to label the
35583582 wedges with their numeric value. The label will be placed inside
35593583 the wedge. If *autopct* is a format string, the label will be
35603584 ``fmt % pct``. If *autopct* is a function, then it will be called.
35613585
3586+ .. admonition:: Discouraged
3587+
3588+ Consider using the *wedge_labels* parameter or `pie_label`
3589+ method instead.
3590+
35623591 pctdistance : float, default: 0.6
35633592 The relative distance along the radius at which the text
35643593 generated by *autopct* is drawn. To draw the text outside the pie,
@@ -3571,6 +3600,11 @@ def pie(self, x, explode=None, labels=None, colors=None,
35713600 If set to ``None``, labels are not drawn but are still stored for
35723601 use in `.legend`.
35733602
3603+ .. deprecated:: 3.12
3604+ From v3.14 *labeldistance* will default to ``None`` and will
3605+ later be removed altogether. Use *wedge_labels* and
3606+ *wedge_label_distance* or the `pie_label` method instead.
3607+
35743608 shadow : bool or dict, default: False
35753609 If bool, whether to draw a shadow beneath the pie. If dict, draw a shadow
35763610 passing the properties in the dict to `.Shadow`.
@@ -3654,6 +3688,26 @@ def pie(self, x, explode=None, labels=None, colors=None,
36543688 fracs = x
36553689 if labels is None :
36563690 labels = ['' ] * len (x )
3691+ else :
3692+ if wedge_labels is not None and labeldistance is not None :
3693+ raise ValueError (
3694+ 'wedge_labels is a replacement for labels when annotating the '
3695+ 'wedges, so the two should not be used together. To add multiple'
3696+ 'sets of labels, use the pie_label method.'
3697+ )
3698+ if labeldistance is False :
3699+ # NB: when the labeldistance default changes, both labeldistance and
3700+ # rotatelabels should be deprecated for removal.
3701+ msg = (
3702+ "From %(removal)s labeldistance will default to None, so that the "
3703+ "strings provided in the labels parameter are only available for "
3704+ "the legend. Later labeldistance will be removed completely. To "
3705+ "preserve existing behavior for now, pass labeldistance=1.1. "
3706+ "Consider using the wedge_labels parameter or the pie_label method "
3707+ "instead of the labels parameter."
3708+ )
3709+ _api .warn_deprecated ("3.12" , message = msg )
3710+ labeldistance = 1.1
36573711 if explode is None :
36583712 explode = [0 ] * len (x )
36593713 if len (x ) != len (labels ):
@@ -3711,11 +3765,16 @@ def get_next_color():
37113765
37123766 pc = PieContainer (slices , x , normalize )
37133767
3714- if labeldistance is None :
3768+ if wedge_labels is not None :
3769+ self .pie_label (pc , wedge_labels , distance = wedge_label_distance ,
3770+ textprops = textprops )
3771+
3772+ elif labeldistance is None :
37153773 # Insert an empty list of texts for backwards compatibility of the
37163774 # return value.
37173775 pc .add_texts ([])
3718- else :
3776+
3777+ if labeldistance is not None :
37193778 # Add labels to the wedges.
37203779 labels_textprops = {
37213780 'fontsize' : mpl .rcParams ['xtick.labelsize' ],
0 commit comments