Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit2dee159

Browse files
authored
Merge branch 'main' into main
2 parents8541748 +dcff41f commit2dee159

28 files changed

+766
-101
lines changed

‎.github/workflows/do_not_merge.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ jobs:
1515
env:
1616
has_tag:>-
1717
${{contains(github.event.pull_request.labels.*.name, 'status: needs comment/discussion') ||
18-
contains(github.event.pull_request.labels.*.name, 'status: waiting for other PR')}}
18+
contains(github.event.pull_request.labels.*.name, 'status: waiting for other PR') ||
19+
contains(github.event.pull_request.labels.*.name, 'DO NOT MERGE') }}
1920
steps:
2021
-name:Check for label
2122
if:${{'true' == env.has_tag}}
2223
run:|
2324
echo "This PR cannot be merged because it has one of the following labels: "
2425
echo "* status: needs comment/discussion"
2526
echo "* status: waiting for other PR"
27+
echo "* DO NOT MERGE"
2628
exit 1
2729
-name:Allow merging
2830
if:${{'false' == env.has_tag}}

‎doc/api/axes_api.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Basic
7373
Axes.eventplot
7474

7575
Axes.pie
76+
Axes.pie_label
7677

7778
Axes.stackplot
7879

‎doc/api/pyplot_summary.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Basic
6464
stem
6565
eventplot
6666
pie
67+
pie_label
6768
stackplot
6869
broken_barh
6970
vlines
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
``PatchCollection`` legends now supported
2+
------------------------------------------
3+
`.PatchCollection` instances now properly display in legends when given a label.
4+
Previously, labels on `~.PatchCollection` objects were ignored by the legend
5+
system, requiring users to create manual legend entries.
6+
7+
..plot::
8+
:include-source: true
9+
:alt: The legend entry displays a rectangle matching the visual properties (colors, line styles, line widths) of the first patch in the collection.
10+
11+
import matplotlib.pyplot as plt
12+
import matplotlib.patches as mpatches
13+
from matplotlib.collections import PatchCollection
14+
15+
fig, ax = plt.subplots()
16+
patches = [mpatches.Circle((0, 0), 0.1), mpatches.Rectangle((0.5, 0.5), 0.2, 0.3)]
17+
pc = PatchCollection(patches, facecolor='blue', edgecolor='black', label='My patches')
18+
ax.add_collection(pc)
19+
ax.legend() # Now displays the label "My patches"
20+
plt.show()
21+
22+
This fix resolves:ghissue:`23998`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Adding labels to pie chart wedges
2+
---------------------------------
3+
4+
The new `~.Axes.pie_label` method adds a label to each wedge in a pie chart created with
5+
`~.Axes.pie`. It can take
6+
7+
* a list of strings, similar to the existing *labels* parameter of `~.Axes.pie`
8+
* a format string similar to the existing *autopct* parameter of `~.Axes.pie` except
9+
that it uses the `str.format` method and it can handle absolute values as well as
10+
fractions/percentages
11+
12+
For more examples, see:doc:`/gallery/pie_and_polar_charts/pie_label`.
13+
14+
..plot::
15+
:include-source: true
16+
:alt: A pie chart with three labels on each wedge, showing a food type, number, and fraction associated with the wedge.
17+
18+
import matplotlib.pyplot as plt
19+
20+
data = [36, 24, 8, 12]
21+
labels = ['spam', 'eggs', 'bacon', 'sausage']
22+
23+
fig, ax = plt.subplots()
24+
pie = ax.pie(data)
25+
26+
ax.pie_label(pie, labels, distance=1.1)
27+
ax.pie_label(pie, '{frac:.1%}', distance=0.7)
28+
ax.pie_label(pie, '{absval:d}', distance=0.4)

‎doc/users/glossary.rst‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
========
2+
Glossary
3+
========
4+
5+
.. Note for glossary authors:
6+
The glossary is primarily intended for Matplotlib's own concepts and
7+
terminology, e.g. figure, artist, backend, etc. We don't want to list
8+
general terms like "GUI framework", "event loop" or similar.
9+
The glossary should contain a short definition of the term, aiming at
10+
a high-level understanding. Use links to redirect to more comprehensive
11+
explanations and API reference when possible.
12+
13+
This glossary defines concepts and terminology specific to Matplotlib.
14+
15+
..glossary::
16+
17+
Figure
18+
The outermost container for a Matplotlib graphic. Think of this as the
19+
canvas to draw on.
20+
21+
This is implemented in the class `.Figure`. For more details see
22+
:ref:`figure-intro`.
23+
24+
Axes
25+
This is a container for what is often colloquially called a plot/chart/graph.
26+
It's a data area with:term:`Axis`\es, i.e. coordinate directions,
27+
and includes data artists like lines, bars etc. as well as
28+
decorations like title, axis labels, legend.
29+
30+
Since most "plotting operations" are realized as methods on `~.axes.Axes`
31+
this is the object users will mostly interact with.
32+
33+
Note: The term *Axes* was taken over from MATLAB. Think of this as
34+
a container spanned by the *x*- and *y*-axis, including decoration
35+
and data.
36+
37+
Axis
38+
A direction with a scale. The scale defines the mapping from
39+
data coordinates to screen coordinates. The Axis also includes
40+
the ticks and axis label.
41+
42+
Artist
43+
The base class for all graphical element that can be drawn.
44+
Examples are Lines, Rectangles, Text, Ticks, Legend, Axes, ...

‎doc/users/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ Using Matplotlib
103103

104104
getting_started/index
105105
../install/index
106+
glossary

‎galleries/examples/misc/svg_filter_pie.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828

2929
# We want to draw the shadow for each pie, but we will not use "shadow"
3030
# option as it doesn't save the references to the shadow patches.
31-
pies=ax.pie(fracs,explode=explode,labels=labels,autopct='%1.1f%%')
31+
pie=ax.pie(fracs,explode=explode,labels=labels,autopct='%1.1f%%')
3232

33-
forwinpies[0]:
33+
forwinpie.wedges:
3434
# set the id with the label.
3535
w.set_gid(w.get_label())
3636

3737
# we don't want to draw the edge of the pie
3838
w.set_edgecolor("none")
3939

40-
forwinpies[0]:
40+
forwinpie.wedges:
4141
# create shadow patch
4242
s=Shadow(w,-0.01,-0.01)
4343
s.set_gid(w.get_gid()+"_shadow")

‎galleries/examples/pie_and_polar_charts/pie_and_donut_labels.py‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
Welcome to the Matplotlib bakery. We will create a pie and a donut
77
chart through the `pie method <matplotlib.axes.Axes.pie>` and
88
show how to label them with a `legend <matplotlib.axes.Axes.legend>`
9-
as well as with `annotations <matplotlib.axes.Axes.annotate>`.
9+
as well as with the `pie_label method <matplotlib.axes.Axes.pie>` and
10+
`annotations <matplotlib.axes.Axes.annotate>`.
1011
"""
1112

1213
# %%
@@ -15,12 +16,14 @@
1516
# Now it's time for the pie. Starting with a pie recipe, we create the data
1617
# and a list of labels from it.
1718
#
18-
# We can provide a function to the ``autopct`` argument, which will expand
19-
# automatic percentage labeling by showing absolute values; we calculate
20-
# the latter back from relative data and the known sum of all values.
19+
# We then create the pie and store the returned `~matplotlib.container.PieContainer`
20+
# object for later.
2121
#
22-
# We then create the pie and store the returned objects for later. The first
23-
# returned element of the returned tuple is a list of the wedges. Those are
22+
# We can provide the `~matplotlib.container.PieContainer` and a format string to
23+
# the `~matplotlib.axes.Axes.pie_label` method to automatically label each
24+
# ingredient's wedge with its weight in grams and percentages.
25+
#
26+
# The `~.PieContainer` has a list of patches as one of its attributes. Those are
2427
# `matplotlib.patches.Wedge` patches, which can directly be used as the handles
2528
# for a legend. We can use the legend's ``bbox_to_anchor`` argument to position
2629
# the legend outside of the pie. Here we use the axes coordinates ``(1, 0, 0.5,
@@ -31,32 +34,26 @@
3134
importmatplotlib.pyplotasplt
3235
importnumpyasnp
3336

34-
fig,ax=plt.subplots(figsize=(6,3),subplot_kw=dict(aspect="equal"))
37+
fig,ax=plt.subplots(figsize=(6,3))
3538

3639
recipe= ["375 g flour",
3740
"75 g sugar",
3841
"250 g butter",
3942
"300 g berries"]
4043

41-
data= [float(x.split()[0])forxinrecipe]
44+
data= [int(x.split()[0])forxinrecipe]
4245
ingredients= [x.split()[-1]forxinrecipe]
4346

47+
pie=ax.pie(data)
4448

45-
deffunc(pct,allvals):
46-
absolute=int(np.round(pct/100.*np.sum(allvals)))
47-
returnf"{pct:.1f}%\n({absolute:d} g)"
48-
49+
ax.pie_label(pie,'{frac:.1%}\n({absval:d}g)',
50+
textprops=dict(color="w",size=8,weight="bold"))
4951

50-
wedges,texts,autotexts=ax.pie(data,autopct=lambdapct:func(pct,data),
51-
textprops=dict(color="w"))
52-
53-
ax.legend(wedges,ingredients,
52+
ax.legend(pie.wedges,ingredients,
5453
title="Ingredients",
5554
loc="center left",
5655
bbox_to_anchor=(1,0,0.5,1))
5756

58-
plt.setp(autotexts,size=8,weight="bold")
59-
6057
ax.set_title("Matplotlib bakery: A pie")
6158

6259
plt.show()
@@ -97,13 +94,13 @@ def func(pct, allvals):
9794

9895
data= [225,90,50,60,100,5]
9996

100-
wedges,texts=ax.pie(data,wedgeprops=dict(width=0.5),startangle=-40)
97+
pie=ax.pie(data,wedgeprops=dict(width=0.5),startangle=-40)
10198

10299
bbox_props=dict(boxstyle="square,pad=0.3",fc="w",ec="k",lw=0.72)
103100
kw=dict(arrowprops=dict(arrowstyle="-"),
104101
bbox=bbox_props,zorder=0,va="center")
105102

106-
fori,pinenumerate(wedges):
103+
fori,pinenumerate(pie.wedges):
107104
ang= (p.theta2-p.theta1)/2.+p.theta1
108105
y=np.sin(np.deg2rad(ang))
109106
x=np.cos(np.deg2rad(ang))
@@ -131,6 +128,7 @@ def func(pct, allvals):
131128
# in this example:
132129
#
133130
# - `matplotlib.axes.Axes.pie` / `matplotlib.pyplot.pie`
131+
# - `matplotlib.axes.Axes.pie_label` / `matplotlib.pyplot.pie_label`
134132
# - `matplotlib.axes.Axes.legend` / `matplotlib.pyplot.legend`
135133
#
136134
# .. tags::
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
===================
3+
Labeling pie charts
4+
===================
5+
6+
This example illustrates some features of the `~matplotlib.axes.Axes.pie_label`
7+
method, which adds labels to an existing pie chart created with
8+
`~matplotlib.axes.Axes.pie`.
9+
"""
10+
11+
# %%
12+
# The simplest option is to provide a list of strings to label each slice of the pie.
13+
14+
importmatplotlib.pyplotasplt
15+
16+
data= [36,24,8,12]
17+
labels= ['spam','eggs','bacon','sausage']
18+
19+
fig,ax=plt.subplots()
20+
pie=ax.pie(data)
21+
ax.pie_label(pie,labels)
22+
23+
# %%
24+
#
25+
# If you want the labels outside the pie, set a *distance* greater than 1.
26+
# This is the distance from the center of the pie as a fraction of its radius.
27+
28+
fig,ax=plt.subplots()
29+
pie=ax.pie(data)
30+
ax.pie_label(pie,labels,distance=1.1)
31+
32+
# %%
33+
#
34+
# You can also rotate the labels so they are oriented away from the pie center.
35+
36+
fig,ax=plt.subplots()
37+
pie=ax.pie(data)
38+
ax.pie_label(pie,labels,rotate=True)
39+
40+
# %%
41+
#
42+
# Instead of explicit labels, pass a format string to label slices with their values...
43+
44+
fig,ax=plt.subplots()
45+
pie=ax.pie(data)
46+
ax.pie_label(pie,'{absval:.1f}')
47+
48+
# %%
49+
#
50+
# ...or with their percentages...
51+
52+
fig,ax=plt.subplots()
53+
pie=ax.pie(data)
54+
ax.pie_label(pie,'{frac:.1%}')
55+
56+
# %%
57+
#
58+
# ...or both.
59+
60+
fig,ax=plt.subplots()
61+
pie=ax.pie(data)
62+
ax.pie_label(pie,'{absval:d}\n{frac:.1%}')
63+
64+
# %%
65+
#
66+
# Font styling can be configured by passing a dictionary to the *textprops* parameter.
67+
68+
fig,ax=plt.subplots()
69+
pie=ax.pie(data)
70+
ax.pie_label(pie,labels,textprops={'fontsize':'large','color':'white'})
71+
72+
# %%
73+
#
74+
# `~matplotlib.axes.Axes.pie_label` can be called repeatedly to add multiple sets
75+
# of labels.
76+
77+
# sphinx_gallery_thumbnail_number = -1
78+
79+
fig,ax=plt.subplots()
80+
pie=ax.pie(data)
81+
82+
ax.pie_label(pie,labels,distance=1.1)
83+
ax.pie_label(pie,'{frac:.1%}',distance=0.7)
84+
ax.pie_label(pie,'{absval:d}',distance=0.4)
85+
86+
plt.show()
87+
88+
# %%
89+
# .. admonition:: References
90+
#
91+
# The use of the following functions, methods, classes and modules is shown
92+
# in this example:
93+
#
94+
# - `matplotlib.axes.Axes.pie` / `matplotlib.pyplot.pie`
95+
# - `matplotlib.axes.Axes.pie_label` / `matplotlib.pyplot.pie_label`
96+
#
97+
# .. tags::
98+
#
99+
# plot-type: pie
100+
# level: beginner

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp