Skip to content

Commit d535cfc

Browse files
committed
FIG Improve figures
1 parent 691de56 commit d535cfc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ch02/figure1.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@
1919

2020
fig,axes = plt.subplots(2, 3)
2121
pairs = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
22+
23+
# Set up 3 different pairs of (color, marker)
24+
color_markers = [
25+
('r', '>'),
26+
('g', 'o'),
27+
('b', 'x'),
28+
]
2229
for i, (p0, p1) in enumerate(pairs):
2330
ax = axes.flat[i]
2431

25-
# Use a different marker/color for each class `t`
26-
for t, marker, c in zip(range(3), ">ox", "rgb"):
32+
for t in range(3):
33+
# Use a different color/marker for each class `t`
34+
c,marker = color_markers[t]
2735
ax.scatter(features[target == t, p0], features[
28-
target == t, p1], marker=marker, c=c, s=40)
36+
target == t, p1], marker=marker, c=c)
2937
ax.set_xlabel(feature_names[p0])
3038
ax.set_ylabel(feature_names[p1])
3139
ax.set_xticks([])

ch02/figure4_5_sklearn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def plot_decision(features, labels, num_neighbors=1):
5858
ax.pcolormesh(X, Y, C, cmap=cmap)
5959
if COLOUR_FIGURE:
6060
cmap = ListedColormap([(1., .0, .0), (.1, .6, .1), (.0, .0, 1.)])
61-
ax.scatter(features[:, 0], features[:, 2], c=labels, cmap=cmap, s=40)
61+
ax.scatter(features[:, 0], features[:, 2], c=labels, cmap=cmap)
6262
else:
6363
for lab, ma in zip(range(3), "Do^"):
6464
ax.plot(features[labels == lab, 0], features[
65-
labels == lab, 2], ma, c=(1., 1., 1.), ms=8)
65+
labels == lab, 2], ma, c=(1., 1., 1.), ms=6)
6666
return fig,ax
6767

6868

0 commit comments

Comments
 (0)