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

Skip to content

Commit e0a84b4

Browse files
committed
use asarray in hist
svn path=/trunk/matplotlib/; revision=8607
1 parent f609ebd commit e0a84b4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

examples/pylab_examples/agg_buffer_to_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib
2-
matplotlib.use('Agg')
2+
#matplotlib.use('Agg')
33
from pylab import figure, show
44
import numpy as np
55

lib/matplotlib/axes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7401,10 +7401,12 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
74017401
**kwargs):
74027402
"""
74037403
call signature::
7404-
7405-
hist(x, bins=10, range=None, normed=False, cumulative=False,
7406-
bottom=None, histtype='bar', align='mid',
7407-
orientation='vertical', rwidth=None, log=False, **kwargs)
7404+
7405+
def hist(x, bins=10, range=None, normed=False, weights=None,
7406+
cumulative=False, bottom=None, histtype='bar', align='mid',
7407+
orientation='vertical', rwidth=None, log=False,
7408+
color=None, label=None,
7409+
**kwargs):
74087410
74097411
Compute and draw the histogram of *x*. The return value is a
74107412
tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
@@ -7567,7 +7569,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
75677569
'this looks transposed (shape is %d x %d)' % x.shape[::-1])
75687570
else:
75697571
# multiple hist with data of different length
7570-
x = [np.array(xi) for xi in x]
7572+
x = [np.asarray(xi) for xi in x]
75717573

75727574
nx = len(x) # number of datasets
75737575

@@ -7582,15 +7584,15 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
75827584
# We need to do to 'weights' what was done to 'x'
75837585
if weights is not None:
75847586
if isinstance(weights, np.ndarray) or not iterable(weights[0]) :
7585-
w = np.array(weights)
7587+
w = np.asarray(weights)
75867588
if w.ndim == 2:
75877589
w = w.T
75887590
elif w.ndim == 1:
75897591
w.shape = (1, w.shape[0])
75907592
else:
75917593
raise ValueError("weights must be 1D or 2D")
75927594
else:
7593-
w = [np.array(wi) for wi in weights]
7595+
w = [np.asarray(wi) for wi in weights]
75947596

75957597
if len(w) != nx:
75967598
raise ValueError('weights should have the same shape as x')

0 commit comments

Comments
 (0)