Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ba9cf1

Browse filesBrowse files
committed
Small cleanups/simplifications/fixes to pie().
- Change the default values of `startangle` and `radius` from "None" to the more explicit 0 and 1. - Apply wedgeprops and textprops separately after the corresponding artist has already been instantiated. This avoids conflicts in case e.g. `textprops` contains an "ha" entry (the dict merge won't notice that this needs to override "horizontalalignment", but applying the user-supplied properties in a second step will "just work". - Misc. small cleanups.
1 parent ee2d046 commit 5ba9cf1
Copy full SHA for 5ba9cf1

File tree

Expand file treeCollapse file tree

3 files changed

+45
-45
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+45
-45
lines changed

‎doc/api/api_changes_3.3/deprecations.rst

Copy file name to clipboardExpand all lines: doc/api/api_changes_3.3/deprecations.rst
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,8 @@ of `.ScalarMappable` are deprecated.
460460
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
461461
All parameters of ``ColorbarBase``, except for the first (*ax*), will become
462462
keyword-only, consistently with ``Colorbar``.
463+
464+
`.Axes.pie` radius and startangle
465+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
466+
Passing ``None`` as either the ``radius`` or ``startangle`` of an `.Axes.pie`
467+
is deprecated; use the explicit defaults of 1 and 0, respectively, instead.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+38-43Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28992899
@_preprocess_data(replace_names=["x", "explode", "labels", "colors"])
29002900
def pie(self, x, explode=None, labels=None, colors=None,
29012901
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
2902-
startangle=None, radius=None, counterclock=True,
2902+
startangle=0, radius=1, counterclock=True,
29032903
wedgeprops=None, textprops=None, center=(0, 0),
29042904
frame=False, rotatelabels=False):
29052905
"""
@@ -2932,7 +2932,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
29322932
autopct : None or str or callable, default: None
29332933
If not *None*, is a string or function used to label the wedges
29342934
with their numeric value. The label will be placed inside the
2935-
wedge. If it is a format string, the label will be ``fmt%pct``.
2935+
wedge. If it is a format string, the label will be ``fmt % pct``.
29362936
If it is a function, it will be called.
29372937
29382938
pctdistance : float, default: 0.6
@@ -2947,12 +2947,12 @@ def pie(self, x, explode=None, labels=None, colors=None,
29472947
If set to ``None``, label are not drawn, but are stored for use in
29482948
``legend()``
29492949
2950-
startangle : float, default: None
2951-
If not *None*, rotates the start of the pie chart by *angle*
2952-
degrees counterclockwise from the x-axis.
2950+
startangle : float, default: 0 degrees
2951+
The angle by which the start of the pie is rotated,
2952+
counterclockwise from the x-axis.
29532953
2954-
radius : float, default: None
2955-
The radius of the pie, if *radius* is *None* it will be set to 1.
2954+
radius : float, default: 1
2955+
The radius of the pie.
29562956
29572957
counterclock : bool, default: True
29582958
Specify fractions direction, clockwise or counterclockwise.
@@ -3030,22 +3030,25 @@ def get_next_color():
30303030
return next(color_cycle)
30313031

30323032
if radius is None:
3033+
cbook.warn_deprecated(
3034+
"3.3", message="Support for passing a radius of None to mean "
3035+
"1 is deprecated since %(since)s and will be removed "
3036+
"%(removal)s.")
30333037
radius = 1
30343038

30353039
# Starting theta1 is the start fraction of the circle
30363040
if startangle is None:
3037-
theta1 = 0
3038-
else:
3039-
theta1 = startangle / 360.0
3041+
cbook.warn_deprecated(
3042+
"3.3", message="Support for passing a startangle of None to "
3043+
"mean 0 is deprecated since %(since)s and will be removed "
3044+
"%(removal)s.")
3045+
startangle = 0
3046+
theta1 = startangle / 360
30403047

3041-
# set default values in wedge_prop
30423048
if wedgeprops is None:
30433049
wedgeprops = {}
3044-
wedgeprops.setdefault('clip_on', False)
3045-
30463050
if textprops is None:
30473051
textprops = {}
3048-
textprops.setdefault('clip_on', False)
30493052

30503053
texts = []
30513054
slices = []
@@ -3061,18 +3064,17 @@ def get_next_color():
30613064
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
30623065
360. * max(theta1, theta2),
30633066
facecolor=get_next_color(),
3064-
**wedgeprops)
3067+
clip_on=False,
3068+
label=label)
3069+
w.set(**wedgeprops)
30653070
slices.append(w)
30663071
self.add_patch(w)
3067-
w.set_label(label)
30683072

30693073
if shadow:
3070-
# make sure to add a shadow after the call to
3071-
# add_patch so the figure and transform props will be
3072-
# set
3074+
# Make sure to add a shadow after the call to add_patch so the
3075+
# figure and transform props will be set.
30733076
shad = mpatches.Shadow(w, -0.02, -0.02)
3074-
shad.set_zorder(0.9 * w.get_zorder())
3075-
shad.set_label('_nolegend_')
3077+
shad.set(zorder=0.9 * w.get_zorder(), label='_nolegend_')
30763078
self.add_patch(shad)
30773079

30783080
if labeldistance is not None:
@@ -3085,14 +3087,13 @@ def get_next_color():
30853087
label_alignment_v = 'bottom' if yt > 0 else 'top'
30863088
label_rotation = (np.rad2deg(thetam)
30873089
+ (0 if xt > 0 else 180))
3088-
props = dict(horizontalalignment=label_alignment_h,
3089-
verticalalignment=label_alignment_v,
3090-
rotation=label_rotation,
3091-
size=rcParams['xtick.labelsize'])
3092-
props.update(textprops)
3093-
3094-
t = self.text(xt, yt, label, **props)
3095-
3090+
t = self.text(xt, yt, label,
3091+
clip_on=False,
3092+
horizontalalignment=label_alignment_h,
3093+
verticalalignment=label_alignment_v,
3094+
rotation=label_rotation,
3095+
size=rcParams['xtick.labelsize'])
3096+
t.set(**textprops)
30963097
texts.append(t)
30973098

30983099
if autopct is not None:
@@ -3105,25 +3106,19 @@ def get_next_color():
31053106
else:
31063107
raise TypeError(
31073108
'autopct must be callable or a format string')
3108-
3109-
props = dict(horizontalalignment='center',
3110-
verticalalignment='center')
3111-
props.update(textprops)
3112-
t = self.text(xt, yt, s, **props)
3113-
3109+
t = self.text(xt, yt, s,
3110+
clip_on=False,
3111+
horizontalalignment='center',
3112+
verticalalignment='center')
3113+
t.set(**textprops)
31143114
autotexts.append(t)
31153115

31163116
theta1 = theta2
31173117

31183118
if not frame:
3119-
self.set_frame_on(False)
3120-
3121-
self.set_xlim((-1.25 + center[0],
3122-
1.25 + center[0]))
3123-
self.set_ylim((-1.25 + center[1],
3124-
1.25 + center[1]))
3125-
self.set_xticks([])
3126-
self.set_yticks([])
3119+
self.set(frame_on=False, xticks=[], yticks=[],
3120+
xlim=(-1.25 + center[0], 1.25 + center[0]),
3121+
ylim=(-1.25 + center[1], 1.25 + center[1]))
31273122

31283123
if autopct is None:
31293124
return slices, texts

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,8 +2648,8 @@ def phase_spectrum(
26482648
def pie(
26492649
x, explode=None, labels=None, colors=None, autopct=None,
26502650
pctdistance=0.6, shadow=False, labeldistance=1.1,
2651-
startangle=None, radius=None, counterclock=True,
2652-
wedgeprops=None, textprops=None, center=(0, 0), frame=False,
2651+
startangle=0, radius=1, counterclock=True, wedgeprops=None,
2652+
textprops=None, center=(0, 0), frame=False,
26532653
rotatelabels=False, *, data=None):
26542654
return gca().pie(
26552655
x, explode=explode, labels=labels, colors=colors,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.