Skip to content

Instantly share code, notes, and snippets.

@jampekka
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jampekka/b375ff0b3b81689ba4a6 to your computer and use it in GitHub Desktop.
Save jampekka/b375ff0b3b81689ba4a6 to your computer and use it in GitHub Desktop.
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