Skip to content

Commit 0a9b7bf

Browse files
committed
RFCT Better use of matplotlib
1 parent a7380bd commit 0a9b7bf

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ch02/figure1.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
target = data['target']
1616

1717

18+
fig,axes = plt.subplots(2, 3)
1819
pairs = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
1920
for i, (p0, p1) in enumerate(pairs):
20-
plt.subplot(2, 3, i + 1)
21+
ax = axes.flat[i]
2122
for t, marker, c in zip(range(3), ">ox", "rgb"):
22-
plt.scatter(features[target == t, p0], features[
23+
ax.scatter(features[target == t, p0], features[
2324
target == t, p1], marker=marker, c=c)
24-
plt.xlabel(feature_names[p0])
25-
plt.ylabel(feature_names[p1])
26-
plt.xticks([])
27-
plt.yticks([])
28-
plt.savefig('figure1.png')
25+
ax.set_xlabel(feature_names[p0])
26+
ax.set_ylabel(feature_names[p1])
27+
ax.set_xticks([])
28+
ax.set_yticks([])
29+
fig.savefig('figure1.png')

0 commit comments

Comments
 (0)