Skip to content

Instantly share code, notes, and snippets.

@bobpoekert
Created February 14, 2019 23:43
Show Gist options
  • Save bobpoekert/5ed5d3a2ae4471d7a63abe676e78aacd to your computer and use it in GitHub Desktop.
Save bobpoekert/5ed5d3a2ae4471d7a63abe676e78aacd to your computer and use it in GitHub Desktop.
def shade(points, width=1280, height=1024):
max_x = np.max(points[:, 0])
max_y = np.max(points[:, 1])
min_x = np.min(points[:, 0])
min_y = np.min(points[:, 1])
bin_width = (max_x - min_x) / width
bin_height = (max_y - min_y) / height
aggs = np.zeros((width, height), dtype=np.uint64)
data_idx = 0
max_data_idx = points.shape[0]
while data_idx < max_data_idx:
x, y = points[data_idx]
res_x = x / bin_width
res_y = y / bin_height
aggs[int(res_x), int(res_y)] += 1
data_idx += 1
aggs = np.log(aggs)
normed_aggs = aggs / np.max(aggs)
return normed_aggs
from PIL import Image
img = shade(big_array_of_points)
from matplotlib.cm import get_cmap
colormap = get_cmap('Blues')
Image.fromarray((colormap(img, alpha=1.0) * 255).astype(np.uint8), mode='RGBA')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment