Actual scaling of the hexes is done by these few lines (polygons in matplotlib are just arrays of vertices):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scale all polygons | |
new_polygons = [] | |
for vs, cnts in zip(polygons, accum_hexscale): | |
xs, ys = vs.T | |
mx = mean(xs) | |
my = mean(ys) | |
sc = hexscale(cnts) | |
xs = (xs-mx)*sc+mx | |
ys = (ys-my)*sc+my | |
new_polygons.append(zip(xs,ys)) | |
polygons = new_polygons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pylab import * | |
from hexbin2 import hexbin2 | |
x = randn(9000) | |
y = randn(9000)/2 | |
hexbin2(x, y, hexscale=lambda x: arctan(x/5) * 2. / pi) |
For radiation data I want hex color to indicate an average radiation in bin's area so reduce_C_function is set to mean. On the other hand uncertainty of measurement is square root of total counts in bin's area, so hexbin_reduce_C_function is set to sum.
Full code prepared as a separate module: https://gist.github.com/anonymous/5278510
Brak komentarzy:
Prześlij komentarz