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

Commit17f1856

Browse files
authored
Revert "Backport PR#11083 on branch v2.2.2-doc"
1 parent37cd83f commit17f1856

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

‎examples/pie_and_polar_charts/pie_demo2.py

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,60 @@
33
Pie Demo2
44
=========
55
6-
Make a pie charts using :meth:`.Axes.pie`.
6+
Make a pie charts of varying size - see
7+
https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.pie for the
8+
docstring.
79
8-
This exampledemonstrates somepiechart features likelabels, varying size,
9-
autolabeling the percentage, offsetting a sliceand adding a shadow.
10-
"""
10+
This exampleshows a basicpiecharts withlabels optional features,
11+
likeautolabeling the percentage, offsetting a slicewith "explode"
12+
and adding a shadow, in different sizes.
1113
14+
"""
1215
importmatplotlib.pyplotasplt
16+
frommatplotlib.gridspecimportGridSpec
1317

1418
# Some data
19+
1520
labels='Frogs','Hogs','Dogs','Logs'
1621
fracs= [15,30,45,10]
1722

18-
# Make figure and axes
19-
fig,axs=plt.subplots(2,2)
20-
21-
# A standard pie plot
22-
axs[0,0].pie(fracs,labels=labels,autopct='%1.1f%%',shadow=True)
23-
24-
# Shift the second slice using explode
25-
axs[0,1].pie(fracs,labels=labels,autopct='%.0f%%',shadow=True,
26-
explode=(0,0.1,0,0))
27-
28-
# Adapt radius and text size for a smaller pie
29-
patches,texts,autotexts=axs[1,0].pie(fracs,labels=labels,
30-
autopct='%.0f%%',
31-
textprops={'size':'smaller'},
32-
shadow=True,radius=0.5)
33-
# Make percent texts even smaller
34-
plt.setp(autotexts,size='x-small')
35-
autotexts[0].set_color('white')
36-
37-
# Use a smaller explode and turn of the shadow for better visibility
38-
patches,texts,autotexts=axs[1,1].pie(fracs,labels=labels,
39-
autopct='%.0f%%',
40-
textprops={'size':'smaller'},
41-
shadow=False,radius=0.5,
42-
explode=(0,0.05,0,0))
43-
plt.setp(autotexts,size='x-small')
44-
autotexts[0].set_color('white')
23+
explode= (0,0.05,0,0)
24+
25+
# Make square figures and axes
26+
27+
the_grid=GridSpec(2,2)
28+
29+
plt.subplot(the_grid[0,0],aspect=1)
30+
31+
plt.pie(fracs,labels=labels,autopct='%1.1f%%',shadow=True)
32+
33+
plt.subplot(the_grid[0,1],aspect=1)
34+
35+
plt.pie(fracs,explode=explode,labels=labels,autopct='%.0f%%',shadow=True)
36+
37+
plt.subplot(the_grid[1,0],aspect=1)
38+
39+
patches,texts,autotexts=plt.pie(fracs,labels=labels,
40+
autopct='%.0f%%',
41+
shadow=True,radius=0.5)
42+
43+
# Make the labels on the small plot easier to read.
44+
fortintexts:
45+
t.set_size('smaller')
46+
fortinautotexts:
47+
t.set_size('x-small')
48+
autotexts[0].set_color('y')
49+
50+
plt.subplot(the_grid[1,1],aspect=1)
51+
52+
# Turn off shadow for tiny plot with exploded slice.
53+
patches,texts,autotexts=plt.pie(fracs,explode=explode,
54+
labels=labels,autopct='%.0f%%',
55+
shadow=False,radius=0.5)
56+
fortintexts:
57+
t.set_size('smaller')
58+
fortinautotexts:
59+
t.set_size('x-small')
60+
autotexts[0].set_color('y')
4561

4662
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp