File: hexbin_demo.py

package info (click to toggle)
matplotlib 0.98.1-1%2Blenny4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,624 kB
  • ctags: 22,599
  • sloc: python: 76,915; cpp: 63,459; ansic: 5,353; makefile: 111; sh: 12
file content (34 lines) | stat: -rw-r--r-- 728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
hexbin is an axes method or pyplot function that is essentially
a pcolor of a 2-D histogram with hexagonal cells.  It can be
much more informative than a scatter plot; in the first subplot
below, try substituting 'scatter' for 'hexbin'.
'''

from matplotlib.pyplot import *
import numpy as np

n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()

subplot(121)
hexbin(x,y)
axis([xmin, xmax, ymin, ymax])
title("Hexagon binning")
cb = colorbar()
cb.set_label('counts')

subplot(122)
hexbin(x,y,bins='log')
axis([xmin, xmax, ymin, ymax])
title("With a log color scale")
cb = colorbar()
cb.set_label('log10(N)')

show()