-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
ENH: introduce wedge_labels parameter for pie
#29152
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
Open
rcomer
wants to merge
1
commit into
matplotlib:main
Choose a base branch
from
rcomer:pie-fmt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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,11 @@ | ||
| ``pie`` *labels* and *labeldistance* parameters | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| Currently the *labels* parameter of `~.Axes.pie` is used both for annotating the | ||
| pie wedges directly, and for automatic legend entries. For consistency | ||
| with other plotting methods, in future *labels* will only be used for the legend. | ||
|
|
||
| The *labeldistance* parameter will therefore default to ``None`` from Matplotlib | ||
| 3.14, when it will also be deprecated and then removed in Matplotlib 3.16. To | ||
| preserve the existing behavior for now, set ``labeldistance=1.1``. For the longer | ||
| term, use the new *wedge_labels* parameter of `~.Axes.pie` or the `~.Axes.pie_label` | ||
| method instead of *labels*. |
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,26 @@ | ||
| New *wedge_labels* parameter for pie | ||
| ------------------------------------ | ||
|
|
||
| `~.Axes.pie` now accepts a *wedge_labels* parameter as a shortcut to the | ||
| `~.Axes.pie_label` method. This may be used for simple annotation of the wedges | ||
| of the pie chart. It can take | ||
|
|
||
| * a list of strings, similar to the existing *labels* parameter | ||
| * a format string similar to the existing *autopct* parameter except that it | ||
| uses the `str.format` method, and it can handle absolute values as well as | ||
| fractions/percentages | ||
|
|
||
| *wedge_labels* has an accompanying *wedge_label_distance* parameter, to control | ||
| the distance of the labels from the center of the pie. | ||
|
|
||
|
|
||
| .. plot:: | ||
| :include-source: true | ||
| :alt: Two pie charts. The chart on the left has labels 'foo' and 'bar' outside the wedges. The chart on the right has labels '1' and '2' inside the wedges. | ||
|
|
||
| import matplotlib.pyplot as plt | ||
|
|
||
| fig, (ax1, ax2) = plt.subplots(ncols=2, layout='constrained') | ||
|
|
||
| ax1.pie([1, 2], wedge_labels=['foo', 'bar'], wedge_label_distance=1.1) | ||
| ax2.pie([1, 2], wedge_labels='{absval:d}', wedge_label_distance=0.6) |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to prohibit
wedge_labels is not None and labels is not None and labeldistance is not None. This would add two sets of labels. Currently, and after deprecation, we'll only add one set of labels.Since
wedge_labelsis new, anybody who sets that could also adapt tolabeldistance=None; and if needed usepie_labelto add the second set of labels.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.