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

Skip to content

Commit a4e2037

Browse files
committed
Merge branch 'hist2d' of https://github.com/piti118/matplotlib into piti118-hist2d
Conflicts: lib/matplotlib/pyplot.py lib/matplotlib/tests/test_axes.py
2 parents 6293484 + fdcc7b4 commit a4e2037

11 files changed

Lines changed: 1145 additions & 69 deletions

File tree

boilerplate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def %(func)s(%(argspec)s):
7171
'fill_betweenx',
7272
'hexbin',
7373
'hist',
74+
'hist2d',
7475
'hlines',
7576
'imshow',
7677
'loglog',
@@ -120,6 +121,7 @@ def %(func)s(%(argspec)s):
120121
'scatter' : 'sci(%(ret)s)',
121122
'pcolor' : 'sci(%(ret)s)',
122123
'pcolormesh': 'sci(%(ret)s)',
124+
'hist2d' : 'sci(%(ret)s[-1])',
123125
'imshow' : 'sci(%(ret)s)',
124126
#'spy' : 'sci(%(ret)s)', ### may return image or Line2D
125127
'quiver' : 'sci(%(ret)s)',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pylab import *
2+
x = randn(1000)
3+
y = randn(1000)+5
4+
5+
#normal distribution center at x=0 and y=5
6+
hist2d(x,y,bins=40)
7+
show()

lib/matplotlib/axes.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7945,6 +7945,70 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
79457945
else:
79467946
return n, bins, cbook.silent_list('Lists of Patches', patches)
79477947

7948+
7949+
@docstring.dedent_interpd
7950+
def hist2d(self, x, y, bins = 10, range=None, normed=False, weights=None,
7951+
cmin=None, cmax=None, **kwargs):
7952+
"""
7953+
Call signature::
7954+
7955+
hist2d(x, y, bins = None, range=None, weights=None, cmin=None, cmax=None **kwargs)
7956+
Make a 2d histogram plot of *x* versus *y*, where *x*,
7957+
*y* are 1-D sequences of the same length
7958+
7959+
The return value is (counts,xedges,yedges,Image)
7960+
7961+
Optional keyword arguments:
7962+
*bins*: [None | int | [int, int] | array_like | [array, array]]
7963+
The bin specification:
7964+
If int, the number of bins for the two dimensions (nx=ny=bins).
7965+
If [int, int], the number of bins in each dimension (nx, ny = bins).
7966+
If array_like, the bin edges for the two dimensions (x_edges=y_edges=bins).
7967+
If [array, array], the bin edges in each dimension (x_edges, y_edges = bins).
7968+
The default value is 10.
7969+
7970+
*range*: [*None* | array_like shape(2,2)]
7971+
The leftmost and rightmost edges of the bins along each dimension (if not specified
7972+
explicitly in the bins parameters): [[xmin, xmax], [ymin, ymax]]. All values outside of
7973+
this range will be considered outliers and not tallied in the histogram.
7974+
7975+
*normed*:[True|False]
7976+
Normalize histogram.
7977+
The default value is False
7978+
7979+
*weights*: [*None* | array]
7980+
An array of values w_i weighing each sample (x_i, y_i).
7981+
7982+
*cmin* : [None| scalar]
7983+
All bins that has count less than cmin will not be displayed
7984+
and these count values in the return value count histogram will also be set to nan upon return
7985+
7986+
*cmax* : [None| scalar]
7987+
All bins that has count more than cmax will not be displayed (set to none before passing to imshow)
7988+
and these count values in the return value count histogram will also be set to nan upon return
7989+
7990+
Remaining keyword arguments are passed directly to :meth:pcolorfast
7991+
7992+
**Example:**
7993+
7994+
.. plot:: mpl_examples/pylab_examples/hist2d_demo.py
7995+
"""
7996+
7997+
# xrange becomes range after 2to3
7998+
bin_range = range
7999+
range = __builtins__["range"]
8000+
h,xedges,yedges = np.histogram2d(x, y, bins=bins, range=bin_range,
8001+
normed=normed, weights=weights)
8002+
8003+
if cmin is not None: h[h<cmin]=None
8004+
if cmax is not None: h[h>cmax]=None
8005+
8006+
pc = self.pcolorfast(xedges,yedges,h.T,**kwargs)
8007+
self.set_xlim(xedges[0],xedges[-1])
8008+
self.set_ylim(yedges[0],yedges[-1])
8009+
8010+
return h,xedges,yedges,pc
8011+
79488012
@docstring.dedent_interpd
79498013
def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
79508014
window=mlab.window_hanning, noverlap=0, pad_to=None,

0 commit comments

Comments
 (0)