Skip to content

Instantly share code, notes, and snippets.

@iv-m
Created January 5, 2017 10:11
Show Gist options
  • Save iv-m/3c9f3187002e4d9ee49175c13fdf1b71 to your computer and use it in GitHub Desktop.
Save iv-m/3c9f3187002e4d9ee49175c13fdf1b71 to your computer and use it in GitHub Desktop.
Script that creates heatmap with log Y and color scales
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
# read the data
x, y = np.loadtxt('responses.dat', unpack=True)
# change absolute timestamps to relative to start, and convert to seconds:
x = (x - x[0]) / 1000.0
# group the data points
log_bins = np.logspace(0, 4, num=100)
H, xedges, yedges = np.histogram2d(x, y, bins=(100, log_bins))
H[H < 0.1] = 0.1
# draw the histogram
plt.rcParams['font.size'] = 10
plt.figure(figsize=(5, 2), dpi=600)
plt.pcolormesh(xedges, yedges, H.T, edgecolors='face',
norm=mpl.colors.LogNorm(), cmap=plt.get_cmap('afmhot'))
plt.axis((xedges[0], xedges[-1], yedges[0], yedges[-1]))
plt.yscale('log')
plt.xlabel('Time, seconds')
plt.ylabel('Latency, ms')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Counts')
# save the image
plt.savefig('plt-heatmap-log-palette-log.png', bbox_inches='tight')
# plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment