Last active
August 29, 2015 14:07
-
-
Save jampekka/b375ff0b3b81689ba4a6 to your computer and use it in GitHub Desktop.
Heatmaphack
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
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