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

Skip to content

Commit f544a83

Browse files
authored
Merge pull request #7066 from phobson/oo-interface-basic-examples
DOC: switch to O-O interface in basic examples
2 parents 57e4809 + 6060e5c commit f544a83

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

examples/lines_bars_and_markers/barh_demo.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66

77

88
plt.rcdefaults()
9+
fig, ax = plt.subplots()
910

1011
# Example data
1112
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
1213
y_pos = np.arange(len(people))
1314
performance = 3 + 10 * np.random.rand(len(people))
1415
error = np.random.rand(len(people))
1516

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?')
17+
ax.barh(y_pos, performance, xerr=error, align='center',
18+
color='green', ecolor='black')
19+
ax.set_yticks(y_pos)
20+
ax.set_yticklabels(people)
21+
ax.invert_yaxis() # labels read top-to-bottom
22+
ax.set_xlabel('Performance')
23+
ax.set_title('How fast do you want to go today?')
2024

2125
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
@@ -10,14 +10,15 @@
1010
from numpy.random import rand
1111

1212

13+
fig, ax = plt.subplots()
1314
for color in ['red', 'green', 'blue']:
1415
n = 750
1516
x, y = rand(2, n)
1617
scale = 200.0 * rand(n)
17-
plt.scatter(x, y, c=color, s=scale, label=color,
18-
alpha=0.3, edgecolors='none')
18+
ax.scatter(x, y, c=color, s=scale, label=color,
19+
alpha=0.3, edgecolors='none')
1920

20-
plt.legend()
21-
plt.grid(True)
21+
ax.legend()
22+
ax.grid(True)
2223

2324
plt.show()

0 commit comments

Comments
 (0)
0