8000 Merge pull request #7066 from phobson/oo-interface-basic-examples · matplotlib/matplotlib@215fbd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 215fbd1

Browse files
committed
Merge pull request #7066 from phobson/oo-interface-basic-examples
DOC: switch to O-O interface in basic examples Conflicts: examples/lines_bars_and_markers/barh_demo.py whitespace vs new code
1 parent 14363c3 commit 215fbd1

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

examples/lines_bars_and_markers/barh_demo.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
import matplotlib.pyplot as plt
88

99

10+
plt.rcdefaults()
11+
fig, ax = plt.subplots()
12+
1013
# Example data
1114
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
1215
y_pos = np.arange(len(people))
1316
performance = 3 + 10 * np.random.rand(len(people))
1417
error = np.random.rand(len(people))
1518

16-
plt.barh(y_pos, performance, xerr=error, align='center')
17-
plt.yticks(y_pos, people)
18-
plt.xlabel('Performance')
19-
plt.title('How fast do you want to go today?')
19+
ax.barh(y_pos, performance, xerr=error, align='center',
20+
color='green', ecolor='black')
21+
ax.set_yticks(y_pos)
22+
ax.set_yticklabels(people)
23+
ax.invert_yaxis() # labels read top-to-bottom
24+
ax.set_xlabel('Performance')
25+
ax.set_title('How fast do you want to go today?')
2026

2127
plt.show()

examples/lines_bars_and_markers/fill_demo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
x = np.linspace(0, 1, 500)
88
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
99

10-
plt.fill(x, y)
11-
plt.grid(True)
10+
fig, ax = plt.subplots()
11+
12+
ax.fill(x, y, zorder=10)
13+
ax.grid(True, zorder=5)
1214
plt.show()

examples/lines_bars_and_markers/fill_demo_features.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
x = np.linspace(0, 2 * np.pi, 500)
1414
y1 = np.sin(x)
1515
y2 = np.sin(3 * x)
16-
plt.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
16+
17+
fig, ax = plt.subplots()
18+
ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
1719
plt.show()

examples/lines_bars_and_markers/line_demo_dash_control.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99

1010

1111
x = np.linspace(0, 10, 500)
12-
line, = plt.plot(x, np.sin(x), '--', linewidth=2)
13-
1412
dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off
15-
line.set_dashes(dashes)
1613

14+
fig, ax = plt.subplots()
15+
line1, = ax.plot(x, np.sin(x), '--', linewidth=2,
16+
label='Dashes set retroactively')
17+
line1.set_dashes(dashes)
18+
19+
line2, = ax.plot(x, -1 * np.sin(x), dashes=[30, 5, 10, 5],
20+
label='Dashes set proactively')
21+
22+
ax.legend(loc='lower right')
1723
plt.show()

examples/lines_bars_and_markers/line_styles_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def nice_repr(text):
2121

2222

2323
# Plot all line styles.
24-
f, ax = plt.subplots()
24+
fig, ax = plt.subplots()
2525

2626
linestyles = ['-', '--', '-.', ':']
2727
for y, linestyle in enumerate(linestyles):

examples/lines_bars_and_markers/scatter_with_legend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from numpy.random import rand
33

44

5+
fig, ax = plt.subplots()
56
for color in ['red', 'green', 'blue']:
67
n = 750
78
x, y = rand(2, n)
89
scale = 200.0 * rand(n)
9-
plt.scatter(x, y, c=color, s=scale, label=color,
10-
alpha=0.3, edgecolors='none')
10+
ax.scatter(x, y, c=color, s=scale, label=color,
11+
alpha=0.3, edgecolors='none')
1112

12-
plt.legend()
13-
plt.grid(True)
13+
ax.legend()
14+
ax.grid(True)
1415

1516
plt.show()

0 commit comments

Comments
 (0)
0