Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
[ENH] hatch keyword for pie + some pie documentation#24470
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletionsdoc/users/next_whats_new/pie_hatch.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
``hatch`` parameter for pie | ||
------------------------------------------- | ||
`~matplotlib.axes.Axes.pie` now accepts a *hatch* keyword that takes as input | ||
a hatch or list of hatches: | ||
.. plot:: | ||
:include-source: true | ||
:alt: Two pie charts, identified as ax1 and ax2, both have a small blue slice, a medium orange slice, and a large green slice. ax1 has a dot hatching on the small slice, a small open circle hatching on the medium slice, and a large open circle hatching on the large slice. ax2 has the same large open circle with a dot hatch on every slice. | ||
fig, (ax1, ax2) = plt.subplots(ncols=2) | ||
x = [10, 30, 60] | ||
ax1.pie(x, hatch=['.', 'o', 'O']) | ||
ax2.pie(x, hatch='.O') | ||
ax1.set_title("hatch=['.', 'o', 'O']") | ||
ax2.set_title("hatch='.O'") |
57 changes: 35 additions & 22 deletionslib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3083,7 +3083,7 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, | ||
startangle=0, radius=1, counterclock=True, | ||
wedgeprops=None, textprops=None, center=(0, 0), | ||
frame=False, rotatelabels=False, *, normalize=True, hatch=None): | ||
""" | ||
Plot a pie chart. | ||
@@ -3109,29 +3109,34 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
A sequence of colors through which the pie chart will cycle. If | ||
*None*, will use the colors in the currently active cycle. | ||
hatch : str or list, default: None | ||
dstansby marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Hatching pattern applied to all pie wedges or sequence of patterns | ||
through which the chart will cycle. For a list of valid patterns, | ||
see :doc:`/gallery/shapes_and_collections/hatch_style_reference`. | ||
.. versionadded:: 3.7 | ||
autopct : None or str or callable, default: None | ||
If not *None*,*autopct*is a string or function used to label the | ||
wedgeswith their numeric value. The label will be placed inside | ||
thewedge. If*autopct* is a format string, the label will be | ||
``fmt % pct``.If*autopct* is a function, then it will be called. | ||
pctdistance : float, default: 0.6 | ||
The relative distance along the radius at which the the text | ||
generated by *autopct* is drawn. To draw the text outside the pie, | ||
set *pctdistance* > 1. This parameter is ignored if *autopct* is | ||
``None``. | ||
labeldistance : float or None, default: 1.1 | ||
The relative distance along the radius at which the labels are | ||
drawn. To draw the labels inside the pie, set *labeldistance* < 1. | ||
If set to ``None``, labels are not drawn but are still stored for | ||
use in `.legend`. | ||
shadow : bool, default: False | ||
Draw a shadow beneath the pie. | ||
startangle : float, default: 0 degrees | ||
The angle by which the start of the pie is rotated, | ||
counterclockwise from the x-axis. | ||
@@ -3143,11 +3148,11 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
Specify fractions direction, clockwise or counterclockwise. | ||
wedgeprops : dict, default: None | ||
Dict of arguments passed toeach `.patches.Wedge` of the pie. | ||
For example, ``wedgeprops = {'linewidth': 3}`` sets the width of | ||
the wedge border lines equal to 3. By default, ``clip_on=False``. | ||
When there is a conflict between these properties and other | ||
keywords, properties passed to *wedgeprops* take precedence. | ||
textprops : dict, default: None | ||
Dict of arguments to pass to the text objects. | ||
@@ -3161,6 +3166,11 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
rotatelabels : bool, default: False | ||
Rotate each label to the angle of the corresponding slice if true. | ||
normalize : bool, default: True | ||
When *True*, always make a full pie by normalizing x so that | ||
``sum(x) == 1``. *False* makes a partial pie if ``sum(x) <= 1`` | ||
and raises a `ValueError` for ``sum(x) > 1``. | ||
data : indexable object, optional | ||
DATA_PARAMETER_PLACEHOLDER | ||
@@ -3215,6 +3225,8 @@ def pie(self, x, explode=None, labels=None, colors=None, | ||
def get_next_color(): | ||
return next(color_cycle) | ||
hatch_cycle = itertools.cycle(np.atleast_1d(hatch)) | ||
_api.check_isinstance(Number, radius=radius, startangle=startangle) | ||
if radius <= 0: | ||
raise ValueError(f'radius must be a positive number, not {radius}') | ||
@@ -3241,6 +3253,7 @@ def get_next_color(): | ||
w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2), | ||
360. * max(theta1, theta2), | ||
facecolor=get_next_color(), | ||
hatch=next(hatch_cycle), | ||
clip_on=False, | ||
label=label) | ||
w.set(**wedgeprops) | ||
4 changes: 2 additions & 2 deletionslib/matplotlib/pyplot.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletionslib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.