8000 EXA change normed to density in matplotlib calls in examples (#12718) · scikit-learn/scikit-learn@f70b1ff · GitHub
[go: up one dir, main page]

Skip to content

Commit f70b1ff

Browse files
adrinjalaliqinhanmin2014
authored andcommitted
EXA change normed to density in matplotlib calls in examples (#12718)
1 parent 7f6cb83 commit f70b1ff

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

examples/compose/plot_transformed_target.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from __future__ import print_function, division
2121

2222
import numpy as np
23+
import matplotlib
2324
import matplotlib.pyplot as plt
25+
from distutils.version import LooseVersion
2426

2527
print(__doc__)
2628

@@ -34,6 +36,13 @@
3436
from sklearn.compose import TransformedTargetRegressor
3537
from sklearn.metrics import median_absolute_error, r2_score
3638

39+
40+
# `normed` is being deprecated in favor of `density` in histograms
41+
if LooseVersion(matplotlib.__version__) >= '2.1':
42+
density_param = {'density': True}
43+
else:
44+
density_param = {'normed': True}
45+
3746
###############################################################################
3847
# A synthetic random regression problem is generated. The targets ``y`` are
3948
# modified by: (i) translating all targets such that all entries are
@@ -54,13 +63,13 @@
5463

5564
f, (ax0, ax1) = plt.subplots(1, 2)
5665

57-
ax0.hist(y, bins=100, normed=True)
66+
ax0.hist(y, bins=100, **density_param)
5867
ax0.set_xlim([0, 2000])
5968
ax0.set_ylabel('Probability')
6069
ax0.set_xlabel('Target')
6170
ax0.set_title('Target distribution')
6271

63-
ax1.hist(y_trans, bins=100, normed=True)
72+
ax1.hist(y_trans, bins=100, **density_param)
6473
ax1.set_ylabel('Probability')
6574
ax1.set_xlabel('Target')
6675
ax1.set_title('Transformed target distribution')
@@ -139,12 +148,12 @@
139148

140149
f, (ax0, ax1) = plt.subplots(1, 2)
141150

142-
ax0.hist(y, bins=100, normed=True)
151+
ax0.hist(y, bins=100, **density_param)
143152
ax0.set_ylabel('Probability')
144153
ax0.set_xlabel('Target')
145154
ax0.set_title('Target distribution')
146155

147-
ax1.hist(y_trans, bins=100, normed=True)
156+
ax1.hist(y_trans, bins=100, **density_param)
148157
ax1.set_ylabel('Probability')
149158
ax1.set_xlabel('Target')
150159
ax1.set_title('Transformed target distribution')

examples/neighbors/plot_kde_1d.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@
2929
# Author: Jake Vanderplas <jakevdp@cs.washington.edu>
3030
#
3131
import numpy as np
32+
import matplotlib
3233
import matplotlib.pyplot as plt
34+
from distutils.version import LooseVersion
3335
from scipy.stats import norm
3436
from sklearn.neighbors import KernelDensity
3537

38+
# `normed` is being deprecated in favor of `density` in histograms
39+
if LooseVersion(matplotlib.__version__) >= '2.1':
40+
density_param = {'density': True}
41+
else:
42+
density_param = {'normed': True}
3643

3744
#----------------------------------------------------------------------
3845
# Plot the progression of histograms to kernels
@@ -47,11 +54,11 @@
4754
fig.subplots_adjust(hspace=0.05, wspace=0.05)
4855

4956
# histogram 1
50-
ax[0, 0].hist(X[:, 0], bins=bins, fc='#AAAAFF', normed=True)
57+
ax[0, 0].hist(X[:, 0], bins=bins, fc='#AAAAFF', **density_param)
5158
ax[0, 0].text(-3.5, 0.31, "Histogram")
5259

5360
# histogram 2
54-
ax[0, 1].hist(X[:, 0], bins=bins + 0.75, fc='#AAAAFF', normed=True)
61+
ax[0, 1].hist(X[:, 0], bins=bins + 0.75, fc='#AAAAFF', **density_param)
5562
ax[0, 1].text(-3.5, 0.31, "Histogram, bins shifted")
5663

5764
# tophat KDE

examples/plot_johnson_lindenstrauss_bound.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@
9494
import sys
9595
from time import time
9696
import numpy as np
97+
import matplotlib
9798
import matplotlib.pyplot as plt
99+
from distutils.version import LooseVersion
98100
from sklearn.random_projection import johnson_lindenstrauss_min_dim
99101
from sklearn.random_projection import SparseRandomProjection
100102
from sklearn.datasets import fetch_20newsgroups_vectorized
101103
from sklearn.datasets import load_digits
102104
from sklearn.metrics.pairwise import euclidean_distances
103105

106+
# `normed` is being deprecated in favor of `density` in histograms
107+
if LooseVersion(matplotlib.__version__) >= '2.1':
108+
density_param = {'density': True}
109+
else:
110+
density_param = {'normed': True}
111+
104112
# Part 1: plot the theoretical dependency between n_components_min and
105113
# n_samples
106114

@@ -187,7 +195,7 @@
187195
% (np.mean(rates), np.std(rates)))
188196

189197
plt.figure()
190-
plt.hist(rates, bins=50, normed=True, range=(0., 2.), edgecolor='k')
198+
plt.hist(rates, bins=50, range=(0., 2.), edgecolor='k', **density_param)
191199
plt.xlabel("Squared distances rate: projected / original")
192200
plt.ylabel("Distribution of samples pairs")
193201
plt.title("Histogram of pairwise distance rates for n_components=%d" %

0 commit comments

Comments
 (0)
0