8000 Small cleanups/simplifications/fixes to pie(). by anntzer · Pull Request #17194 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Small cleanups/simplifications/fixes to pie(). #17194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,8 @@ of `.ScalarMappable` are deprecated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All parameters of ``ColorbarBase``, except for the first (*ax*), will become
keyword-only, consistently with ``Colorbar``.

`.Axes.pie` radius and startangle
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Passing ``None`` as either the ``radius`` or ``startangle`` of an `.Axes.pie`
is deprecated; use the explicit defaults of 1 and 0, respectively, instead.
81 changes: 38 additions & 43 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
@_preprocess_data(replace_names=["x", "explode", "labels", "colors"])
def pie(self, x, explode=None, labels=None, colors=None,
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
startangle=None, radius=None, counterclock=True,
startangle=0, radius=1, counterclock=True,
wedgeprops=None, textprops=None, center=(0, 0),
frame=False, rotatelabels=False):
"""
Expand Down Expand Up @@ -2932,7 +2932,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
autopct : None or str or callable, default: None
If not *None*, is a string or function used to label the wedges
with their numeric value. The label will be placed inside the
wedge. If it is a format string, the label will be ``fmt%pct``.
wedge. If it is a format string, the label will be ``fmt % pct``.
If it is a function, it will be called.

pctdistance : float, default: 0.6
Expand All @@ -2947,12 +2947,12 @@ def pie(self, x, explode=None, labels=None, colors=None,
If set to ``None``, label are not drawn, but are stored for use in
``legend()``

startangle : float, default: None
If not *None*, rotates the start of the pie chart by *angle*
degrees counterclockwise from the x-axis.
startangle : float, default: 0 degrees
The angle by which the start of the pie is rotated,
counterclockwise from the x-axis.

radius : float, default: None
The radius of the pie, if *radius* is *None* it will be set to 1.
radius : float, default: 1
The radius of the pie.

counterclock : bool, default: True
Specify fractions direction, clockwise or counterclockwise.
Expand Down Expand Up @@ -3030,22 +3030,25 @@ def get_next_color():
return next(color_cycle)

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

# Starting theta1 is the start fraction of the circle
if startangle is None:
theta1 = 0
else:
theta1 = startangle / 360.0
cbook.warn_deprecated(
"3.3", message="Support for passing a startangle of None to "
"mean 0 is deprecated since %(since)s and will be removed "
"%(removal)s.")
startangle = 0
theta1 = startangle / 360

# set default values in wedge_prop
if wedgeprops is None:
wedgeprops = {}
wedgeprops.setdefault('clip_on', False)

if textprops is None:
textprops = {}
textprops.setdefault('clip_on', False)

texts = []
slices = []
Expand All @@ -3061,18 +3064,17 @@ def get_next_color():
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
360. * max(theta1, theta2),
facecolor=get_next_color(),
**wedgeprops)
8000 clip_on=False,
label=label)
w.set(**wedgeprops)
slices.append(w)
self.add_patch(w)
w.set_label(label)

if shadow:
# make sure to add a shadow after the call to
# add_patch so the figure and transform props will be
# set
# Make sure to add a shadow after the call to add_patch so the
# figure and transform props will be set.
shad = mpatches.Shadow(w, -0.02, -0.02)
shad.set_zorder(0.9 * w.get_zorder())
shad.set_label('_nolegend_')
shad.set(zorder=0.9 * w.get_zorder(), label='_nolegend_')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason these parameters are not passed directly to Shadow?

I'm also wondering if we need to specify the label, because by default an Artist should not have any label.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, likely because of bad interaction with #16098.
Also by default Shadow inherits the parent patch (the Wedge)'s props, including the label. Again perhaps this should be changed on Shadow, but heh.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, was here before. I'll close my eyes and move on.

self.add_patch(shad)

if labeldistance is not None:
Expand All @@ -3085,14 +3087,13 @@ def get_next_color():
label_alignment_v = 'bottom' if yt > 0 else 'top'
label_rotation = (np.rad2deg(thetam)
+ (0 if xt > 0 else 180))
props = dict(horizontalalignment=label_alignment_h,
verticalalignment=label_alignment_v,
rotation=label_rotation,
size=rcParams['xtick.labelsize'])
props.update(textprops)

t = self.text(xt, yt, label, **props)

t = self.text(xt, yt, label,
clip_on=False,
horizontalalignment=label_alignment_h,
verticalalignment=label_alignment_v,
rotation=label_rotation,
size=rcParams['xtick.labelsize'])
t.set(**textprops)
texts.append(t)

if autopct is not None:
Expand All @@ -3105,25 +3106,19 @@ def get_next_color():
else:
raise TypeError(
'autopct must be callable or a format string')

props = dict(horizontalalignment='center',
verticalalignment='center')
props.update(textprops)
t = self.text(xt, yt, s, **props)

t = self.text(xt, yt, s,
clip_on=False,
horizontalalignment='center',
verticalalignment='center')
t.set(**textprops)
autotexts.append(t)

theta1 = theta2

if not frame:
self.set_frame_on(False)

self.set_xlim((-1.25 + center[0],
1.25 + center[0]))
self.set_ylim((-1.25 + center[1],
1.25 + center[1]))
self.set_xticks([])
self.set_yticks([])
self.set(frame_on=False, xticks=[], yticks=[],
xlim=(-1.25 + center[0], 1.25 + center[0]),
ylim=(-1.25 + center[1], 1.25 + center[1]))

if autopct is None:
return slices, texts
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up 5C0B @@ -2648,8 +2648,8 @@ def phase_spectrum(
def pie(
x, explode=None, labels=None, colors=None, autopct=None,
pctdistance=0.6, shadow=False, labeldistance=1.1,
startangle=None, radius=None, counterclock=True,
wedgeprops=None, textprops=None, center=(0, 0), frame=False,
startangle=0, radius=1, counterclock=True, wedgeprops=None,
textprops=None, center=(0, 0), frame=False,
rotatelabels=False, *, data=None):
return gca().pie(
x, explode=explode, labels=labels, colors=colors,
Expand Down
0