@@ -2900,7 +2900,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
29002900 autopct = None , pctdistance = 0.6 , shadow = False , labeldistance = 1.1 ,
29012901 startangle = 0 , radius = 1 , counterclock = True ,
29022902 wedgeprops = None , textprops = None , center = (0 , 0 ),
2903- frame = False , rotatelabels = False ):
2903+ frame = False , rotatelabels = False , * , normalize = None ):
29042904 """
29052905 Plot a pie chart.
29062906
@@ -2941,6 +2941,19 @@ def pie(self, x, explode=None, labels=None, colors=None,
29412941 shadow : bool, default: False
29422942 Draw a shadow beneath the pie.
29432943
2944+ normalize: None or bool, default: None
2945+ When *True*, always make a full pie by normalizing x so that
2946+ ``sum(x) == 1``. *False* makes a partial pie if ``sum(x) <= 1``
2947+ and raises a `ValueError` for ``sum(x) > 1``.
2948+
2949+ When *None*, defaults to *True* if ``sum(x) > 0`` and *False* if
2950+ ``sum(x) < 1``.
2951+
2952+ Please note that the previous default value of *None* is now
2953+ deprecated, and the default will change to *True* in the next
2954+ release. Please pass ``normalize=False`` explicitly if you want to
2955+ draw a partial pie.
2956+
29442957 labeldistance : float or None, default: 1.1
29452958 The radial distance at which the pie labels are drawn.
29462959 If set to ``None``, label are not drawn, but are stored for use in
@@ -3005,9 +3018,22 @@ def pie(self, x, explode=None, labels=None, colors=None,
30053018 raise ValueError ("Wedge sizes 'x' must be non negative values" )
30063019
30073020 sx = x .sum ()
3008- if sx > 1 :
3009- x = x / sx
30103021
3022+ if normalize is None :
3023+ if sx < 1 :
3024+ cbook .warn_deprecated (
3025+ "3.3" , message = "normalize=None does not normalize "
3026+ "if the sum is less than 1 but this behavior"
3027+ "is deprecated since %(since)s until %(removal)s. "
3028+ "After the deprecation "
3029+ "period the default value will be normalize=True. "
3030+ "To prevent normalization pass normalize=False " )
3031+ else :
3032+ normalize = True
3033+ if normalize :
3034+ x = x / sx
3035+ elif sx > 1 :
3036+ raise ValueError ('Cannot plot an unnormalized pie with sum(x) > 1' )
30113037 if labels is None :
30123038 labels = ['' ] * len (x )
30133039 if explode is None :
0 commit comments