Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 117b57b

Browse files
committed
Axes.hist: remove unnecessary copying of input array.
svn path=/trunk/matplotlib/; revision=8267
1 parent 3a1f7e3 commit 117b57b

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7289,17 +7289,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
72897289

72907290
if isinstance(x, np.ndarray):
72917291
# TODO: support masked arrays;
7292-
# Why is the copy needed?
7293-
x = np.array(x, copy=True, subok=False)
7292+
x = np.asarray(x)
72947293
if x.ndim == 2:
7295-
x = x.T
7294+
x = x.T # 2-D input with columns as datasets; switch to rows
72967295
elif x.ndim == 1:
7297-
x.shape = (1, x.shape[0])
7296+
x = x.reshape(1, x.shape[0]) # new view, single row
72987297
else:
72997298
raise ValueError("x must be 1D or 2D")
73007299
if x.shape[1] < x.shape[0]:
7301-
warnings.warn('2D hist input should be nsamples x nvariables; '
7302-
'this looks transposed')
7300+
warnings.warn('2D hist input should be nsamples x nvariables;\n '
7301+
'this looks transposed (shape is %d x %d)' % x.shape[::-1])
73037302
else:
73047303
# multiple hist with data of different length
73057304
x = [np.array(xi) for xi in x]

0 commit comments

Comments
 (0)