Skip to content

Commit 654bddd

Browse files
committed
FIX Explicitly specify the plot colors for each curve
1 parent 04ca448 commit 654bddd

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

examples/linear_model/plot_lasso_coordinate_descent_path.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Author: Alexandre Gramfort <[email protected]>
1414
# License: BSD 3 clause
1515

16+
from itertools import cycle
1617
import numpy as np
1718
import matplotlib.pyplot as plt
1819

@@ -47,9 +48,13 @@
4748

4849
plt.figure(1)
4950
ax = plt.gca()
50-
ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])
51-
l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)
52-
l2 = plt.plot(-np.log10(alphas_enet), coefs_enet.T, linestyle='--')
51+
52+
colors = cycle(['b', 'r', 'g', 'c', 'k'])
53+
neg_log_alphas_lasso = -np.log10(alphas_lasso)
54+
neg_log_alphas_enet = -np.log10(alphas_enet)
55+
for coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):
56+
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
57+
l2 = plt.plot(neg_log_alphas_enet, coef_e, linestyle='--', c=c)
5358

5459
plt.xlabel('-Log(alpha)')
5560
plt.ylabel('coefficients')
@@ -60,10 +65,10 @@
6065

6166
plt.figure(2)
6267
ax = plt.gca()
63-
ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])
64-
l1 = plt.plot(-np.log10(alphas_lasso), coefs_lasso.T)
65-
l2 = plt.plot(-np.log10(alphas_positive_lasso), coefs_positive_lasso.T,
66-
linestyle='--')
68+
neg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso)
69+
for coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):
70+
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
71+
l2 = plt.plot(neg_log_alphas_positive_lasso, coef_pl, linestyle='--', c=c)
6772

6873
plt.xlabel('-Log(alpha)')
6974
plt.ylabel('coefficients')
@@ -74,10 +79,10 @@
7479

7580
plt.figure(3)
7681
ax = plt.gca()
77-
ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])
78-
l1 = plt.plot(-np.log10(alphas_enet), coefs_enet.T)
79-
l2 = plt.plot(-np.log10(alphas_positive_enet), coefs_positive_enet.T,
80-
linestyle='--')
82+
neg_log_alphas_positive_enet = -np.log10(alphas_positive_enet)
83+
for (coef_e, coef_pe, c) in zip(coefs_enet, coefs_positive_enet, colors):
84+
l1 = plt.plot(neg_log_alphas_enet, coef_e, c=c)
85+
l2 = plt.plot(neg_log_alphas_positive_enet, coef_pe, linestyle='--', c=c)
8186

8287
plt.xlabel('-Log(alpha)')
8388
plt.ylabel('coefficients')

examples/linear_model/plot_ridge_path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
# Display results
4848

4949
ax = plt.gca()
50-
ax.set_color_cycle(['b', 'r', 'g', 'c', 'k', 'y', 'm'])
5150

5251
ax.plot(alphas, coefs)
5352
ax.set_xscale('log')

0 commit comments

Comments
 (0)