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

Appearance settings

Commit 17f1856

Browse filesBrowse files
authored
Revert "Backport PR #11083 on branch v2.2.2-doc"
1 parent 37cd83f commit 17f1856
Copy full SHA for 17f1856

File tree

Expand file treeCollapse file tree

1 file changed

+47
-31
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+47
-31
lines changed

‎examples/pie_and_polar_charts/pie_demo2.py

Copy file name to clipboardExpand all lines: examples/pie_and_polar_charts/pie_demo2.py
+47-31Lines 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 example demonstrates some pie chart features like labels, varying size,
9-
autolabeling the percentage, offsetting a slice and adding a shadow.
10-
"""
10+
This example shows a basic pie charts with labels optional features,
11+
like autolabeling the percentage, offsetting a slice with "explode"
12+
and adding a shadow, in different sizes.
1113
14+
"""
1215
import matplotlib.pyplot as plt
16+
from matplotlib.gridspec import GridSpec
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+
for t in texts:
45+
t.set_size('smaller')
46+
for t in autotexts:
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+
for t in texts:
57+
t.set_size('smaller')
58+
for t in autotexts:
59+
t.set_size('x-small')
60+
autotexts[0].set_color('y')
4561

4662
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.