Skip to content

Commit 258f2fb

Browse files
author
Sam Vaughan
committed
Changed fill.py example to be less misleading, after issue #5827
1 parent adaa8e5 commit 258f2fb

File tree

1 file changed

+20
-8
lines changed
  • examples/lines_bars_and_markers

1 file changed

+20
-8
lines changed

examples/lines_bars_and_markers/fill.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@
55
66
Demo fill plot.
77
"""
8+
9+
###############################################################################
10+
# First, the most basic fill plot a user can make with matplotlib:
811
import numpy as np
912
import matplotlib.pyplot as plt
1013

11-
x = np.linspace(0, 1, 500)
12-
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
1314

14-
###############################################################################
15-
# First, the most basic fill plot a user can make with matplotlib:
15+
x = [0, 0, 1, 2, 2]
16+
y = [0, 1, 2, 1, 0]
1617

1718
fig, ax = plt.subplots()
18-
1919
ax.fill(x, y, zorder=10)
2020
ax.grid(True, zorder=5)
2121

22-
x = np.linspace(0, 2 * np.pi, 500)
23-
y1 = np.sin(x)
24-
y2 = np.sin(3 * x)
22+
2523

2624
###############################################################################
2725
# Next, a few more optional features:
@@ -30,6 +28,20 @@
3028
# * Setting the fill color.
3129
# * Setting the opacity (alpha value).
3230

31+
32+
x = np.linspace(0, 1.5 * np.pi, 500)
33+
y1 = np.sin(x)
34+
y2 = np.sin(3 * x)
35+
3336
fig, ax = plt.subplots()
37+
3438
ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
39+
40+
# Also outline the region we've filled in
41+
ax.plot(x, y1, c='b', alpha=0.8)
42+
ax.plot(x, y2, c='r', alpha=0.8)
43+
ax.plot([x[0], x[-1]], [y1[0], y1[-1]], c='b', alpha=0.8)
44+
ax.plot([x[0], x[-1]], [y2[0], y2[-1]], c='r', alpha=0.8)
45+
46+
3547
plt.show()

0 commit comments

Comments
 (0)