Skip to content

[MRG+1] Fix: Replace pylab with matplotlib.pyplot #6754 #6762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
59c4209
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 4, 2016
0e08eab
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 5, 2016
0ac6c7d
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 5, 2016
e8f9efc
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 5, 2016
4786962
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 5, 2016
361957f
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 6, 2016
28c946b
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 6, 2016
9e40520
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 6, 2016
41bb999
Fix: Replace pylab with matplotlib.pyplot #6754
ztultrebor May 6, 2016
5c2e9f5
refactor: Replace pl with plt
ztultrebor May 8, 2016
a4c2692
refactor: Replace pl with plt
ztultrebor May 8, 2016
86533f8
refactor: Replace pl with plt
ztultrebor May 8, 2016
531b770
refactor: Replace pl with plt
ztultrebor May 8, 2016
f3276aa
refactor: Replace pl with plt
ztultrebor May 8, 2016
57126a1
fix: Fix bug that prevented graphs from displaying
ztultrebor May 9, 2016
3cd9786
refactor: Replace pl with plt
ztultrebor May 9, 2016
22bb3b8
refactor: Replace pl with plt
ztultrebor May 9, 2016
5868f4b
refactor: Replace pl with plt
ztultrebor May 9, 2016
9fb5290
refactor: Replace pl with plt
ztultrebor May 9, 2016
2df3acd
docs: removed pylab references from comments
ztultrebor May 9, 2016
9df9225
docs: removed all pylab references
ztultrebor May 9, 2016
82c08ac
docs: removed pylab references from comments
ztultrebor May 9, 2016
32d574e
docs: removed all pylab references
ztultrebor May 9, 2016
4f0bb78
refactor: Replace pl with plt
ztultrebor May 9, 2016
4b97a07
refactor: Replace pl with plt
ztultrebor May 9, 2016
4207d90
refactor: Replace pl with plt
ztultrebor May 9, 2016
2582513
docs: removed all pylab references
ztultrebor May 9, 2016
918ed58
docs: removed all pylab references
ztultrebor May 9, 2016
af26318
refactor: Replace pl with plt
ztultrebor May 9, 2016
45514ee
docs: removed all pylab references
ztultrebor May 9, 2016
93482ad
docs: removed all pylab references
ztultrebor May 9, 2016
0f82942
style: Indent properly
ztultrebor May 10, 2016
4095006
style: indent properly
ztultrebor May 10, 2016
fd9407e
style: Indent properly
ztultrebor May 10, 2016
6ad9fc6
docs: Add missing .pyplot
ztultrebor May 10, 2016
d327902
docs: Fix typo
ztultrebor May 10, 2016
040b365
style: Indent properly
ztultrebor May 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions benchmarks/bench_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if __name__ == '__main__':

import pylab as pl
import matplotlib.pyplot as plt

n_iter = 40

Expand Down Expand Up @@ -46,13 +46,13 @@
lasso.fit(X, Y)
time_lasso[i] = total_seconds(datetime.now() - start)

pl.figure('scikit-learn GLM benchmark results')
pl.xlabel('Dimensions')
pl.ylabel('Time (s)')
pl.plot(dimensions, time_ridge, color='r')
pl.plot(dimensions, time_ols, color='g')
pl.plot(dimensions, time_lasso, color='b')
plt.figure('scikit-learn GLM benchmark results')
plt.xlabel('Dimensions')
plt.ylabel('Time (s)')
plt.plot(dimensions, time_ridge, color='r')
plt.plot(dimensions, time_ols, color='g')
plt.plot(dimensions, time_lasso, color='b')

pl.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left')
pl.axis('tight')
pl.show()
plt.legend(['Ridge', 'OLS', 'LassoLars'], loc='upper left')
plt.axis('tight')
plt.show()
38 changes: 19 additions & 19 deletions benchmarks/bench_glmnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef):
if __name__ == '__main__':
from glmnet.elastic_net import Lasso as GlmnetLasso
from sklearn.linear_model import Lasso as ScikitLasso
# Delayed import of pylab
import pylab as pl
# Delayed import of matplotlib.pyplot
import matplotlib.pyplot as plt

scikit_results = []
glmnet_results = []
Expand Down Expand Up @@ -76,15 +76,15 @@ def bench(factory, X, Y, X_test, Y_test, ref_coef):
print("benchmarking glmnet: ")
glmnet_results.append(bench(GlmnetLasso, X, Y, X_test, Y_test, coef_))

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

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

xx = np.arange(100, 100 + n * step, step)
pl.figure('scikit-learn vs. glmnet benchmark results')
pl.title('Regression in high dimensional spaces (%d samples)' % n_samples)
pl.plot(xx, scikit_results, 'b-', label='scikit-learn')
pl.plot(xx, glmnet_results, 'r-', label='glmnet')
pl.legend()
pl.xlabel('number of features')
pl.ylabel('Time (s)')
pl.axis('tight')
pl.show()
plt.figure('scikit-learn vs. glmnet benchmark results')
plt.title('Regression in high dimensional spaces (%d samples)' % n_samples)
plt.plot(xx, scikit_results, 'b-', label='scikit-learn')
plt.plot(xx, glmnet_results, 'r-', label='glmnet')
plt.legend()
plt.xlabel('number of features')
plt.ylabel('Time (s)')
plt.axis('tight')
plt.show()
39 changes: 20 additions & 19 deletions benchmarks/bench_lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def compute_bench(alpha, n_samples, n_features, precompute):

if __name__ == '__main__':
from sklearn.linear_model import Lasso, LassoLars
import pylab as pl
import matplotlib.pyplot as plt

alpha = 0.01 # regularization parameter

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

pl.figure('scikit-learn LASSO benchmark results')
pl.subplot(211)
pl.plot(list_n_samples, lasso_results, 'b-',
plt.figure('scikit-learn LASSO benchmark results')
plt.subplot(211)
plt.plot(list_n_samples, lasso_results, 'b-',
label='Lasso')
pl.plot(list_n_samples, lars_lasso_results, 'r-',
plt.plot(list_n_samples, lars_lasso_results, 'r-',
label='LassoLars')
pl.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features, alpha))
pl.legend(loc='upper left')
pl.xlabel('number of samples')
pl.ylabel('Time (s)')
pl.axis('tight')
plt.title('precomputed Gram matrix, %d features, alpha=%s' % (n_features,
alpha))
plt.legend(loc='upper left')
plt.xlabel('number of samples')
plt.ylabel('Time (s)')
plt.axis('tight')

n_samples = 2000
list_n_features = np.linspace(500, 3000, 5).astype(np.int)
lasso_results, lars_lasso_results = compute_bench(alpha, [n_samples],
list_n_features, precompute=False)
pl.subplot(212)
pl.plot(list_n_features, lasso_results, 'b-', label='Lasso')
pl.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars')
pl.title('%d samples, alpha=%s' % (n_samples, alpha))
pl.legend(loc='upper left')
pl.xlabel('number of features')
pl.ylabel('Time (s)')
pl.axis('tight')
pl.show()
plt.subplot(212)
plt.plot(list_n_features, lasso_results, 'b-', label='Lasso')
plt.plot(list_n_features, lars_lasso_results, 'r-', label='LassoLars')
plt.title('%d samples, alpha=%s' % (n_samples, alpha))
plt.legend(loc='upper left')
plt.xlabel('number of features')
plt.ylabel('Time (s)')
plt.axis('tight')
plt.show()
48 changes: 24 additions & 24 deletions benchmarks/bench_plot_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from time import time

import numpy as np
import pylab as pl
import matplotlib.pyplot as plt
from matplotlib import ticker

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

pl.figure(figsize=(8, 11))
plt.figure(figsize=(8, 11))

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

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

c_bar = pl.bar(xvals, build_time[alg] - bottom,
width, bottom, color='r')
q_bar = pl.bar(xvals, query_time[alg],
width, build_time[alg], color='b')
c_bar = plt.bar(xvals, build_time[alg] - bottom,
width, bottom, color='r')
q_bar = plt.bar(xvals, query_time[alg],
width, build_time[alg], color='b')

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

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

pl.ylabel('Time (s)')
plt.ylabel('Time (s)')

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

descr_string = descr_string[:-2]

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

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

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

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

if __name__ == '__main__':
barplot_neighbors(dataset='digits')
barplot_neighbors(dataset='dense')
pl.show()
plt.show()
24 changes: 12 additions & 12 deletions benchmarks/bench_plot_omp_lars.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ def compute_bench(samples_range, features_range):
results = compute_bench(samples_range, features_range)
max_time = max(np.max(t) for t in results.values())

import pylab as pl
fig = pl.figure('scikit-learn OMP vs. LARS benchmark results')
import matplotlib.pyplot as plt
fig = plt.figure('scikit-learn OMP vs. LARS benchmark results')
for i, (label, timings) in enumerate(sorted(results.iteritems())):
ax = fig.add_subplot(1, 2, i)
ax = fig.add_subplot(1, 2, i+1)
vmax = max(1 - timings.min(), -1 + timings.max())
pl.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax)
plt.matshow(timings, fignum=False, vmin=1 - vmax, vmax=1 + vmax)
ax.set_xticklabels([''] + map(str, samples_range))
ax.set_yticklabels([''] + map(str, features_range))
pl.xlabel('n_samples')
pl.ylabel('n_features')
pl.title(label)

pl.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63)
ax = pl.axes([0.1, 0.08, 0.8, 0.06])
pl.colorbar(cax=ax, orientation='horizontal')
pl.show()
plt.xlabel('n_samples')
plt.ylabel('n_features')
plt.title(label)

plt.subplots_adjust(0.1, 0.08, 0.96, 0.98, 0.4, 0.63)
ax = plt.axes([0.1, 0.08, 0.8, 0.06])
plt.colorbar(cax=ax, orientation='horizontal')
plt.show()
18 changes: 9 additions & 9 deletions benchmarks/bench_plot_parallel_pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License: BSD 3 clause
import time

import pylab as pl
import matplotlib.pyplot as plt

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

pl.figure('scikit-learn parallel %s benchmark results' % func.__name__)
pl.plot(sample_sizes, one_core, label="one core")
pl.plot(sample_sizes, multi_core, label="multi core")
pl.xlabel('n_samples')
pl.ylabel('Time (s)')
pl.title('Parallel %s' % func.__name__)
pl.legend()
plt.figure('scikit-learn parallel %s benchmark results' % func.__name__)
plt.plot(sample_sizes, one_core, label="one core")
plt.plot(sample_sizes, multi_core, label="multi core")
plt.xlabel('n_samples')
plt.ylabel('Time (s)')
plt.title('Parallel %s' % func.__name__)
plt.legend()

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

plot(euclidean_distances)
plot(rbf_kernels)
pl.show()
plt.show()
22 changes: 11 additions & 11 deletions benchmarks/bench_plot_ward.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from scipy.cluster import hierarchy
import pylab as pl
import matplotlib.pyplot as plt

from sklearn.cluster import AgglomerativeClustering

Expand All @@ -31,13 +31,13 @@

ratio = scikits_time / scipy_time

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