Skip to content

Commit

Permalink
Added colorblind capability
Browse files Browse the repository at this point in the history
  • Loading branch information
johannah committed Oct 23, 2015
1 parent 5a58e56 commit f48d0a0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/mixture/plot_gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
dpgmm = mixture.DPGMM(n_components=5, covariance_type='full')
dpgmm.fit(X)

color_iter = itertools.cycle(['r', 'g', 'b', 'c', 'm'])
color_iter = itertools.cycle(['navy', 'c', 'cornflowerblue', 'gold',
'darkorange'])

for i, (clf, title) in enumerate([(gmm, 'GMM'),
(dpgmm, 'Dirichlet Process GMM')]):
Expand Down
12 changes: 7 additions & 5 deletions examples/mixture/plot_gmm_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
from sklearn.mixture import GMM


colors = ['navy', 'turquoise', 'darkorange']
def make_ellipses(gmm, ax):
for n, color in enumerate('rgb'):
for n, color in enumerate(colors):
v, w = np.linalg.eigh(gmm._get_covars()[n][:2, :2])
u = w[0] / np.linalg.norm(w[0])
angle = np.arctan2(u[1], u[0])
Expand Down Expand Up @@ -91,14 +92,15 @@ def make_ellipses(gmm, ax):
h = plt.subplot(2, n_classifiers / 2, index + 1)
make_ellipses(classifier, h)

for n, color in enumerate('rgb'):
for n, color in enumerate(colors):
data = iris.data[iris.target == n]
plt.scatter(data[:, 0], data[:, 1], 0.8, color=color,
plt.scatter(data[:, 0], data[:, 1], s=0.8, color=color,
label=iris.target_names[n])
# Plot the test data with crosses
for n, color in enumerate('rgb'):
for n, color in enumerate(colors):
data = X_test[y_test == n]
plt.plot(data[:, 0], data[:, 1], 'x', color=color)
print(color)
plt.scatter(data[:, 0], data[:, 1], marker='x', color=color)

y_train_pred = classifier.predict(X_train)
train_accuracy = np.mean(y_train_pred.ravel() == y_train.ravel()) * 100
Expand Down
3 changes: 2 additions & 1 deletion examples/mixture/plot_gmm_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
best_gmm = gmm

bic = np.array(bic)
color_iter = itertools.cycle(['k', 'r', 'g', 'b', 'c', 'm', 'y'])
color_iter = itertools.cycle(['navy', 'turquoise', 'cornflowerblue',
'darkorange'])
clf = best_gmm
bars = []

Expand Down
7 changes: 3 additions & 4 deletions examples/mixture/plot_gmm_sin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
X[i, 0] = x + np.random.normal(0, 0.1)
X[i, 1] = 3 * (np.sin(x) + np.random.normal(0, .2))


color_iter = itertools.cycle(['r', 'g', 'b', 'c', 'm'])

color_iter = itertools.cycle(['navy', 'turquoise', 'cornflowerblue',
'darkorange'])

for i, (clf, title) in enumerate([
(mixture.GMM(n_components=10, covariance_type='full', n_iter=100),
Expand All @@ -63,7 +62,7 @@
# components.
if not np.any(Y_ == i):
continue
plt.scatter(X[Y_ == i, 0], X[Y_ == i, 1], .8, color=color)
plt.scatter(X[Y_ == i, 0], X[Y_ == i, 1], color=color, s=4)

# Plot an ellipse to show the Gaussian component
angle = np.arctan(u[1] / u[0])
Expand Down

0 comments on commit f48d0a0

Please sign in to comment.