Skip to content

Instantly share code, notes, and snippets.

@jampekka
Last active Aug 29, 2015
Embed
What would you like to do?
Heatmaphack
import numpy as np, matplotlib.pyplot as plt, sys
from scipy.ndimage.filters import gaussian_filter
def transparent_jet(cutoff=0.2):
colormap = plt.cm.get_cmap('jet')
colormap._init()
alphas = np.linspace(0.0, 1.0, colormap.N)
alphas[alphas < cutoff] = 0.0
alphas[alphas > cutoff] = 1.0
colormap._lut[:-3,-1] = alphas
return colormap
xy = np.loadtxt(sys.stdin)
Z, xe, ye = np.histogram2d(*xy.T, bins=xy.ptp(axis=0)/10.0)
heat = gaussian_filter(Z, 100.0, mode='nearest')
print "image_extent: ", xe[0], xe[-1], ye[0], ye[-1]
print "value_range:", np.min(Z), np.max(Z)
print "heat_range:", np.min(heat), np.max(heat)
plt.imsave(sys.argv[1], heat, cmap=transparent_jet())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment