Heatmap in matplotlib


In [1]:
%load_ext watermark
%watermark -a 'Hideki Tanaka' -u -d -v -p matplotlib,numpy


Hideki Tanaka 
last updated: 2016-02-23 

CPython 3.5.1
IPython 4.1.1

matplotlib 1.5.1
numpy 1.10.4

In [2]:
%matplotlib inline

In [3]:
import matplotlib.pyplot as plt
import numpy as np

In [4]:
plt.style.use('ggplot')
plt.rc('xtick.major', size=0)
plt.rc('ytick.major', size=0)

In [5]:
data = np.random.rand(10, 10)*1e-5

In [6]:
clim_min = 0
clim_max = 1e-5
ticks = np.linspace(clim_min, clim_max, 6)

In [7]:
fig, ax = plt.subplots()
cm = plt.cm.get_cmap('jet')
im = ax.imshow(data, cmap=cm, interpolation='sinc')
im.set_clim(clim_min, clim_max)
fig.colorbar(im, ticks=ticks, format='%.1e')
ax.xaxis.set_major_locator(plt.NullLocator())
ax.yaxis.set_major_locator(plt.NullLocator())
plt.show()



In [8]:
fig.savefig('../images/mpl_heatmap.png', dpi=80)