8000 Backport PR #11009: Changed fill.py example to be less misleading · matplotlib/matplotlib@f742f0a · GitHub
[go: up one dir, main page]

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

8000
Appearance settings

Commit f742f0a

Browse files
jklymakMeeseeksDev[bot]
authored andcommitted
Backport PR #11009: Changed fill.py example to be less misleading
1 parent edd5854 commit f742f0a

File tree

1 file changed

+20
-12
lines changed
  • examples/lines_bars_and_markers

1 file changed

+20
-12
lines changed

examples/lines_bars_and_markers/fill.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
66
Demo fill plot.
77
"""
8-
import numpy as np
9-
import matplotlib.pyplot as plt
10-
11-
x = np.linspace(0, 1, 500)
12-
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
138

149
###############################################################################
1510
# First, the most basic fill plot a user can make with matplotlib:
11+
import numpy as np
12+
import matplotlib.pyplot as plt
1613

17-
fig, ax = plt.subplots()
18-
19-
ax.fill(x, y, zorder=10)
20-
ax.grid(True, zorder=5)
14+
x = [0, 1, 2, 1]
15+
y = [1, 2, 1, 0]
2116

22-
x = np.linspace(0, 2 * np.pi, 500)
23-
y1 = np.sin(x)
24-
y2 = np.sin(3 * x)
17+
fig, ax = plt.subplots()
18+
ax.fill(x, y)
19+
plt.show()
2520

2621
###############################################################################
2722
# Next, a few more optional features:
@@ -30,6 +25,19 @@
3025
# * Setting the fill color.
3126
# * Setting the opacity (alpha value).
3227

28+
29+
x = np.linspace(0, 1.5 * np.pi, 500)
30+
y1 = np.sin(x)
31+
y2 = np.sin(3 * x)
32+
3333
fig, ax = plt.subplots()
34+
3435
ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
36+
37+
# Outline of the region we've filled in
38+
ax.plot(x, y1, c='b', alpha=0.8)
39+
ax.plot(x, y2, c='r', alpha=0.8)
40+
ax.plot([x[0], x[-1]], [y1[0], y1[-1]], c='b', alpha=0.8)
41+
ax.plot([x[0], x[-1]], [y2[0], y2[-1]], c='r', alpha=0.8)
42+
3543
plt.show()

0 commit comments

Comments
 (0)
0