8000 [MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 (#6762) · scikit-learn/scikit-learn@0c879ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c879ba

Browse files
ztultreborTomDLT
authored andcommitted
[MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 (#6762)
* Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 22 occurrences of pylab replaced with matplotlib.pyplot - bench_glm.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 21 remaining occurrences of pylab replaced with matplotlib.pyplot - bench_glmnet.py now free of pylab references - code does not execute for extraneous reason: ImportError: No module named glmnet.elastic_net * Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 19 occurrences of pylab replaced with matplotlib.pyplot - bench_lasso.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 18 occurrences of pylab replaced with matplotlib.pyplot - bench_plot_neighbors.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - one instance of 17 occurrences of pylab replaced with matplotlib.pyplot - bench_plot_omp_lars.py now free of pylab references - code does not execute for extraneous reasons: - File "bench_plot_omp_lars.py", line 111, in <module> - ax = fig.add_subplot(1, 2, i) - ValueError: num must be 1 <= num <= 2, not 0 - line 111 should probably be ax = fig.add_subplot(1, 2, i+1) * Fix: Replace pylab with matplotlib.pyplot #6754 - bench_plot_parallel_pairwise.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - bench_plot_ward.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - bench_sgd_regression.py now free of pylab references - code executes properly * Fix: Replace pylab with matplotlib.pyplot #6754 - bench_tree.py now free of pylab references - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_glm.py clean * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_glm.py clean of pl - code does not execute for extraneous reasons * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_lasso.py clean of pl - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_neighbors.py clean of pl - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_omp_lars.py clean of pl - code does not execute for extraneous reasons * fix: Fix bug that prevented graphs from displaying * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_parallel_pairwise.py clean of pl - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_plot_ward.py clean of pl - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_sgd_regression.py clean of pl - code executes properly * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - bench_tree.py clean of pl - code executes properly * docs: removed pylab references from comments * docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt * docs: removed pylab references from comments - replaced with matplotlib.pyplot - pl --> plt * docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - mlcomp_sparse_document_classification.py clean of pl * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_gpr_noisy_targets.py clean of pl - code does not execute for extraneous reasons - File "examples/gaussian_process/plot_gpr_noisy_targets.py", line 31, in <module> - from sklearn.gaussian_process import GaussianProcessRegressor - ImportError: cannot import name GaussianProcessRegressor * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_gpc_isoprobability.py clean of pl - code does not execute for extraneous reasons - File "examples/gaussian_process/plot_gpc_isoprobability.py", line 24, in <module> - from sklearn.gaussian_process import GaussianProcessClassifier - ImportError: cannot import name GaussianProcessClassifier * docs: removed all pylab references - replaced with matplotlib.pyplot - pl --> plt * docs: removed all pylab references - replaced with matplotlib.pyplot * refactor: Replace pl with plt - replace instances of pl (as on import pylab as pl) with plt (as in import matplotlib.pyplot as plt) - plot_sparse_coding.py clean of pl - code executes properly * docs: removed all pylab references - replaced with matplotlib.pyplot * docs: removed all pylab references - replaced with matplotlib.pyplot * style: Indent properly * style: indent properly * style: Indent properly * docs: Add missing .pyplot * docs: Fix typo * style: Indent properly
1 parent a249821 commit 0c879ba

21 files changed

+231
-231
lines changed

benchmarks/bench_glm.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
if __name__ == '__main__':
1414

15-
import pylab as pl
15+
import matplotlib.pyplot as plt
1616

1717
n_iter = 40
1818

@@ -46,13 +46,13 @@
4646
lasso.fit(X, Y)
4747
time_lasso[i] = total_seconds(datetime.now() - start)
4848

49-
pl.figure('scikit-learn GLM benchmark results')
50-
pl.xlabel('Dimensions')
51-
pl.ylabel('Time (s)')
52-
pl.plot(dimensions, time_ridge, color='r')
53-
pl.plot(dimensions, time_ols, color='g')
54-
pl.plot(dimensions, time_lasso, color='b')
49+
plt.figure('scikit-learn GLM benchmark results')
50+
plt.xlabel('Dimensions')
51+
plt.ylabel('Time (s)')
52+
plt.plot(dimensions, time_ridge, color='r')
53+
plt.plot(dimensions, time_ols, color='g')
54+
plt.plot(dimensions, time_lasso, color='b')
5555

56-
pl.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left')
57-
pl.axis('tight')
58-
pl.show()
56+
plt.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left')
57+
plt.axis('tight')
58+
plt.show()

benchmarks/bench_glmnet.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef):
4747
if __name__ == '__main__':
4848
from glmnet.elastic_net import Lasso as GlmnetLasso
4949
from sklearn.linear_model import Lasso as ScikitLasso
50-
# Delayed import of pylab
51-
import pylab as pl
50+
# Delayed import of matplotlib.pyplot
51+
import matplotlib.pyplot as plt
5252

5353
scikit_results = []
5454
glmnet_results = []
@@ -76,15 +76,15 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef):
7676
print("benchmarking glmnet: ")
7777
glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_))
7878

79-
pl.clf()
79+
plt.clf()
8080
xx = range(0, n * step, step)
81-
pl.title('Lasso regression on sample dataset (%d features)' % n_features)
82-
pl.plot(xx, scikit_results, 'b-', label='scikit-learn')
83-
pl.plot(xx, glmnet_results, 'r-', label='glmnet')
84-
pl.legend()
85-
pl.xlabel('number of samples to classify')
86-
pl.ylabel('Time (s)')
87-
pl.show()
81+
plt.title('Lasso regression on sample dataset (%d features)' % n_features)
82+
plt.plot(xx, scikit_results, 'b-', label='scikit-learn')
83+
plt.plot(xx, glmnet_results, 'r-', label='glmnet')
84+
plt.legend()
85+
plt.xlabel('number of samples to classify')
86+
plt.ylabel('Time (s)')
87+
plt.show()
8888

8989
# now do a benchmark where the number of points is fixed
9090
# and the variable is the number of features
@@ -117,12 +117,12 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef):
117117
glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_))
118118

119119
xx = np.arange(100, 100 + n * step, step)
120-
pl.figure('scikit-learn vs. glmnet benchmark results')
121-
pl.title('Regression in high dimensional spaces (%d samples)' % n_samples)
122-
pl.plot(xx, scikit_results, 'b-', label='scikit-learn')
123-
pl.plot(xx, glmnet_results, 'r-', label='glmnet')
124-
pl.legend()
125-
pl.xlabel('number of features')
126-
pl.ylabel('Time (s)')
127-
pl.axis('tight')
128-
pl.show()
120+
plt.figure('scikit-learn vs. glmnet benchmark results')
121+
plt.title('Regression in high dimensional spaces (%d samples)' % n_samples)
122+
plt.plot(xx, scikit_results, 'b-', label='scikit-learn')
123+
plt.plot(xx, glmnet_results, 'r-', label='glmnet')
124+
plt.legend()
125+
plt.xlabel('number of features')
126+
plt.ylabel('Time (s)')
127+
plt.axis('tight')
128+
plt.show()

benchmarks/bench_lasso.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def compute_bench(alpha, n_samples, n_features, precompute):
5959

6060
if __name__ == '__main__':
6161
from sklearn.linear_model import Lasso, LassoLars
62-
import pylab as pl
62+
import matplotlib.pyplot as plt
6363

6464
alpha = 0.01 # regularization parameter
6565

@@ -68,28 +68,29 @@ def compute_bench(alpha, n_samples, n_features, precompute):
6868
lasso_results, lars_lasso_results = compute_bench(alpha, list_n_samples,
6969
[n_features], precompute=True)
7070

71-
pl.figure('scikit-learn LASSO benchmark results')
72-
pl.subplot(211)
73-
pl.plot(list_n_samples, lasso_results, 'b-',
71+
plt.figure('scikit-learn LASSO benchmark results')
72+
plt.subplot(211)
73+
plt.plot(list_n_samples, lasso_results, 'b-',
7474
label='Lasso')
75-
pl.plot(list_n_samples, lars_lasso_results, 'r-',
75+
plt.plot(list_n_samples, lars_lasso_results, 'r-',
7676
label='LassoLars')
77-
pl.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, alpha))
78-
pl.legend(loc='upper left')
79-
pl.xlabel('number of samples')
80-
pl.ylabel('Time (s)')
81-
pl.axis('tight')
77+
plt.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features,
78+
alpha))
79+
plt.legend(loc='upper left')
80+
plt.xlabel('number of samples')
81+
plt.ylabel('Time (s)')
82+
plt.axis('tight')
8283

8384
n_samples = 2000
8485
list_n_features = np.linspace(500, 3000, 5).astype(np.int)
8586
lasso_results, lars_lasso_results = compute_bench(alpha, [n_samples],
8687
list_n_features, precompute=False)
87-
pl.subplot(212)
88-
pl.plot(list_n_features, lasso_results, 'b-', label='Lasso')
89-
pl.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars')
90-
pl.title('%d samples, alpha=%s' % (n_samples, alpha))
91-
pl.legend(loc='upper left')
92-
pl.xlabel('number of features')
93-
pl.ylabel('Time (s)')
94-
pl.axis('tight')
95-
pl.show()
88+
plt.subplot(212)
89+
plt.plot(list_n_features, lasso_results, 'b-', label='Lasso')
90+
plt.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars')
91+
plt.title('%d samples, alpha=%s' % (n_samples, alpha))
92+
plt.legend(loc='upper left')
93+
plt.xlabel('number of features')
94+
plt.ylabel('Time (s)')
95+
plt.axis('tight')
96+
plt.show()

benchmarks/bench_plot_neighbors.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from time import time
55

66
import numpy as np
7-
import pylab as pl
7+
import matplotlib.pyplot as plt
88
from matplotlib import ticker
99

1010
from sklearn import neighbors, datasets
@@ -106,7 +106,7 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11),
106106
k_results_build[algorithm][i] = (t1 - t0)
107107
k_results_query[algorithm][i] = (t2 - t1)
108108

109-
pl.figure(figsize=(8, 11))
109+
plt.figure(figsize=(8, 11))
110110

111111
for (sbplt, vals, quantity,
112112
build_time, query_time) in [(311, Nrange, 'N',
@@ -118,8 +118,8 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11),
118118
(313, krange, 'k',
119119
k_results_build,
120120
k_results_query)]:
121-
ax = pl.subplot(sbplt, yscale='log')
122- 10000
pl.grid(True)
121+
ax = plt.subplot(sbplt, yscale='log')
122+
plt.grid(True)
123123

124124
tick_vals = []
125125
tick_labels = []
@@ -131,21 +131,21 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11),
131131
xvals = 0.1 + i * (1 + len(vals)) + np.arange(len(vals))
132132
width = 0.8
133133

134-
c_bar = pl.bar(xvals, build_time[alg] - bottom,
135-
width, bottom, color='r')
136-
q_bar = pl.bar(xvals, query_time[alg],
137-
width, build_time[alg], color='b')
134+
c_bar = plt.bar(xvals, build_time[alg] - bottom,
135+
width, bottom, color='r')
136+
q_bar = plt.bar(xvals, query_time[alg],
137+
width, build_time[alg], color='b')
138138

139139
tick_vals += list(xvals + 0.5 * width)
140140
tick_labels += ['%i' % val for val in vals]
141141

142-
pl.text((i + 0.02) / len(algorithms), 0.98, alg,
143-
transform=ax.transAxes,
144-
ha='left',
145-
va='top',
146-
bbox=dict(facecolor='w', edgecolor='w', alpha=0.5))
142+
plt.text((i + 0.02) / len(algorithms), 0.98, alg,
143+
transform=ax.transAxes,
144+
ha='left',
145+
va='top',
146+
bbox=dict(facecolor='w', edgecolor='w', alpha=0.5))
147147

148-
pl.ylabel('Time (s)')
148+
plt.ylabel('Time (s)')
149149

150150
ax.xaxis.set_major_locator(ticker.FixedLocator(tick_vals))
151151
ax.xaxis.set_major_formatter(ticker.FixedFormatter(tick_labels))
@@ -166,20 +166,20 @@ def barplot_neighbors(Nrange=2 ** np.arange(1, 11),
166166

167167
descr_string = descr_string[:-2]
168168

169-
pl.text(1.01, 0.5, title_string,
170-
transform=ax.transAxes, rotation=-90,
171-
ha='left', va='center', fontsize=20)
169+
plt.text(1.01, 0.5, title_string,
170+
transform=ax.transAxes, rotation=-90,
171+
ha='left', va='center', fontsize=20)
172172

173-
pl.text(0.99, 0.5, descr_string,
174-
transform=ax.transAxes, rotation=-90,
175-
ha='right', va='center')
173+
plt.text(0.99, 0.5, descr_string,
174+
transform=ax.transAxes, rotation=-90,
175+
ha='right', va='center')
176176

177-
pl.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16)
177+
plt.gcf().suptitle("%s data set" % dataset.capitalize(), fontsize=16)
178178

179-
pl.figlegend((c_bar, q_bar), ('construction', 'N-point query'),
180-
'upper right')
179+
plt.figlegend((c_bar, q_bar), ('construction', 'N-point query'),
180+
'upper right')
181181

182182
if __name__ == '__main__':
183183
barplot_neighbors(dataset='digits')
184184
barplot_neighbors(dataset='dense')
185-
pl.show()
185+
plt.show()

benchmarks/bench_plot_omp_lars.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ def compute_bench(samples_range, features_range):
105105
results = compute_bench(samples_range, features_range)
106106
max_time = max(np.max(t) for t in results.values())
107107

108-
import pylab as pl
109-
fig = pl.figure('scikit-learn OMP vs. LARS benchmark results')
108+
import matplotlib.pyplot as plt
109+
fig = plt.figure('scikit-learn OMP vs. LARS benchmark results')
110110
for i, (label, timings) in enumerate(sorted(results.iteritems())):
111-
ax = fig.add_subplot(1, 2, i)
111+
ax = fig.add_subplot(1, 2, i+1)
112112
vmax = max(1 - timings.min(), -1 + timings.max())
113-
pl.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax)
113+
plt.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax)
114114
ax.set_xticklabels([''] + map(str, samples_range))
115115
ax.set_yticklabels([''] + map(str, features_range))
116-
pl.xlabel('n_samples')
117-
pl.ylabel('n_features')
118-
pl.title(label)
119-
120-
pl.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63)
121-
ax = pl.axes([0.1, 0.08, 0.8, 0.06])
122-
pl.colorbar(cax=ax, orientation='horizontal')
123-
pl.show()
116+
plt.xlabel('n_samples')
117+
plt.ylabel('n_features')
118+
plt.title(label)
119+
120+
plt.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63)
121+
ax = plt.axes([0.1, 0.08, 0.8, 0.06])
122+
plt.colorbar(cax=ax, orientation='horizontal')
123+
plt.show()

benchmarks/bench_plot_parallel_pairwise.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License: BSD 3 clause
33
import time
44

5-
import pylab as pl
5+
import matplotlib.pyplot as plt
66

77
from sklearn.utils import check_random_state
88
from sklearn.metrics.pairwise import pairwise_distances
@@ -25,13 +25,13 @@ def plot(func):
2525
func(X, n_jobs=-1)
2626
multi_core.append(time.time() - start)
2727

28-
pl.figure('scikit-learn parallel %s benchmark results' % func.__name__)
29-
pl.plot(sample_sizes, one_core, label="one core")
30-
pl.plot(sample_sizes, multi_core, label="multi core")
31-
pl.xlabel('n_samples')
32-
pl.ylabel('Time (s)')
33-
pl.title('Parallel %s' % func.__name__)
34-
pl.legend()
28+
plt.figure('scikit-learn parallel %s benchmark results' % func.__name__)
29+
plt.plot(sample_sizes, one_core, label="one core")
30+
plt.plot(sample_sizes, multi_core, label="multi core")
31+
plt.xlabel('n_samples')
32+
plt.ylabel('Time (s)')
33+
plt.title('Parallel %s' % func.__name__)
34+
plt.legend()
3535

3636
def euclidean_distances(X, n_jobs):
3737
return pairwise_distances(X, metric="euclidean", n_jobs=n_jobs)
@@ -41,4 +41,4 @@ def rbf_kernels(X, n_jobs):
4141

4242
plot(euclidean_distances)
4343
plot(rbf_kernels)
44-
pl.show()
44+
plt.show()

benchmarks/bench_plot_ward.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
from scipy.cluster import hierarchy
9-
import pylab as pl
9+
import matplotlib.pyplot as plt
1010

1111
from sklearn.cluster import AgglomerativeClustering
1212

@@ -31,13 +31,13 @@
3131

3232
ratio = scikits_time / scipy_time
3333

34-
pl.figure("scikit-learn Ward's method benchmark results")
35-
pl.imshow(np.log(ratio), aspect='auto', origin="lower")
36-
pl.colorbar()
37-
pl.contour(ratio, levels=[1, ], colors='k')
38-
pl.yticks(range(len(n_features)), n_features.astype(np.int))
39-
pl.ylabel('N features')
40-
pl.xticks(range(len(n_samples)), n_samples.astype(np.int))
41-
pl.xlabel('N samples')
42-
pl.title("Scikit's time, in units of scipy time (log)")
43-
pl.show()
34+
plt.figure("scikit-learn Ward's method benchmark results")
35+
plt.imshow(np.log(ratio), aspect='auto', origin="lower")
36+
plt.colorbar()
37+
plt.contour(ratio, levels=[1, ], colors='k')
38+
plt.yticks(range(len(n_features)), n_features.astype(np.int))
39+
plt.ylabel('N features')
40+
plt.xticks(range(len(n_samples)), n_samples.astype(np.int))
41+
plt.xlabel('N samples')
42+
plt.title("Scikit's time, in units of scipy time (log)")
43+
plt.show()

0 commit comments

Comments
 (0)
0