Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
ENH: introduce PieContainer and pie_label method#30733
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
Open
rcomer wants to merge1 commit intomatplotlib:mainChoose a base branch fromrcomer:pie_label
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.
+499 −87
Open
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
1 change: 1 addition & 0 deletionsdoc/api/axes_api.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 |
|---|---|---|
| @@ -73,6 +73,7 @@ Basic | ||
| Axes.eventplot | ||
| Axes.pie | ||
| Axes.pie_label | ||
| Axes.stackplot | ||
1 change: 1 addition & 0 deletionsdoc/api/pyplot_summary.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 |
|---|---|---|
| @@ -64,6 +64,7 @@ Basic | ||
| stem | ||
| eventplot | ||
| pie | ||
| pie_label | ||
| stackplot | ||
| broken_barh | ||
| vlines | ||
28 changes: 28 additions & 0 deletionsdoc/release/next_whats_new/pie_label.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,28 @@ | ||
| Adding labels to pie chart wedges | ||
| --------------------------------- | ||
| The new `~.Axes.pie_label` method adds a label to each wedge in a pie chart created with | ||
| `~.Axes.pie`. It can take | ||
| * a list of strings, similar to the existing *labels* parameter of `~.Axes.pie` | ||
| * a format string in analogy to the existing *autopct* parameter of `~.Axes.pie` except | ||
| that it uses the `str.format` method, and it can handle absolute values as well as | ||
| fractions/percentages | ||
| For more examples, see:doc:`/gallery/pie_and_polar_charts/pie_label`. | ||
| ..plot:: | ||
| :include-source: true | ||
| :alt: A pie chart with three labels on each wedge, showing a food type, number and fraction associated with the wedge. | ||
| import matplotlib.pyplot as plt | ||
| data = [36, 24, 8, 12] | ||
| labels = ['spam', 'eggs', 'bacon', 'sausage'] | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels, distance=1.1) | ||
| ax.pie_label(pie, '{frac:.1%}', distance=0.7) | ||
| ax.pie_label(pie, '{absval:d}', distance=0.4) |
6 changes: 3 additions & 3 deletionsgalleries/examples/misc/svg_filter_pie.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
38 changes: 18 additions & 20 deletionsgalleries/examples/pie_and_polar_charts/pie_and_donut_labels.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
100 changes: 100 additions & 0 deletionsgalleries/examples/pie_and_polar_charts/pie_label.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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """ | ||
| =================== | ||
| Labeling pie charts | ||
| =================== | ||
| This example illustrates some features of the `~matplotlib.axes.Axes.pie_label` | ||
| method, which adds labels to an existing pie chart created with | ||
| `~matplotlib.axes.Axes.pie`. | ||
| """ | ||
| # %% | ||
| # The simplest option is to provide a list of strings to label each slice of the pie. | ||
| import matplotlib.pyplot as plt | ||
| data = [36, 24, 8, 12] | ||
| labels = ['spam', 'eggs', 'bacon', 'sausage'] | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels) | ||
| # %% | ||
| # | ||
| # If you want the labels outside the pie, set a *distance* greater than 1. | ||
| # This is the distance from the center of the pie as a fraction of its radius. | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels, distance=1.1) | ||
| # %% | ||
| # | ||
| # You can also rotate the labels so they are oriented away from the pie center. | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels, rotate=True) | ||
| # %% | ||
| # | ||
| # Instead of explicit labels, pass a format string to label slices with their values... | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, '{absval:.1f}') | ||
| # %% | ||
| # | ||
| # ...or with their percentages... | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, '{frac:.1%}') | ||
| # %% | ||
| # | ||
| # ...or both. | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, '{absval:d}\n{frac:.1%}') | ||
| # %% | ||
| # | ||
| # Font styling can be configured by passing a dictionary to the *textprops* parameter. | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels, textprops={'fontsize': 'large', 'color': 'white'}) | ||
| # %% | ||
| # | ||
| # `~matplotlib.axes.Axes.pie_label` can be called repeatedly to add multiple sets | ||
| # of labels. | ||
| # sphinx_gallery_thumbnail_number = -1 | ||
| fig, ax = plt.subplots() | ||
| pie = ax.pie(data) | ||
| ax.pie_label(pie, labels, distance=1.1) | ||
| ax.pie_label(pie, '{frac:.1%}', distance=0.7) | ||
| ax.pie_label(pie, '{absval:d}', distance=0.4) | ||
| plt.show() | ||
| # %% | ||
| # .. admonition:: References | ||
| # | ||
| # The use of the following functions, methods, classes and modules is shown | ||
| # in this example: | ||
| # | ||
| # - `matplotlib.axes.Axes.pie` / `matplotlib.pyplot.pie` | ||
| # - `matplotlib.axes.Axes.pie_label` / `matplotlib.pyplot.pie_label` | ||
| # | ||
| # .. tags:: | ||
| # | ||
| # plot-type: pie | ||
| # level: beginner |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.