Sebastian Raschka

<- [back] to the matplotlib-gallery repository




In [10]:
%load_ext watermark


The watermark extension is already loaded. To reload it, use:
  %reload_ext watermark

In [11]:
%watermark -u -d -v -p matplotlib,numpy


Last updated: 15/07/2014 

CPython 3.4.1
IPython 2.0.0

matplotlib 1.3.1
numpy 1.8.1

[More information](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) about the `watermark` magic command extension.


In [12]:
%matplotlib inline



Sections





Simple heat maps


In [4]:
import numpy as np

# Sample from a bivariate Gaussian distribution
mean = [0,0]
cov = [[0,1],[1,0]] 
x, y = np.random.multivariate_normal(mean, cov, 10000).T



Using NumPy's histogram2d


In [5]:
from matplotlib import pyplot as plt

hist, xedges, yedges = np.histogram2d(x,y)
X,Y = np.meshgrid(xedges,yedges)
plt.imshow(hist)
plt.grid(True)
plt.colorbar()
plt.show()



In [6]:
# changing the interpolation

plt.imshow(hist, interpolation='nearest')
plt.grid(True)
plt.colorbar()
plt.show()




Using hist2d from matplotlib pyplot


In [7]:
plt.hist2d(x, y, bins=10)
plt.colorbar()
plt.grid()
plt.show()



In [8]:
# changing the bin-size

plt.hist2d(x, y, bins=40)
plt.colorbar()
plt.grid()
plt.show()




Using pcolor from matplotlib pyplot


In [9]:
plt.pcolor(hist)
plt.colorbar()
plt.grid()
plt.show()




Using different color maps



Available color maps


In [27]:
from math import ceil
import numpy as np

# Sample from a bivariate Gaussian distribution
mean = [0,0]
cov = [[0,1],[1,0]] 
x, y = np.random.multivariate_normal(mean, cov, 10000).T


size = len(plt.cm.datad.keys())
all_maps = list(plt.cm.datad.keys())

fig, ax = plt.subplots(ceil(size/4), 4, figsize=(12,100))

counter = 0
for row in ax:
    for col in row:
        try:
            col.imshow(hist, cmap=all_maps[counter])
            col.set_title(all_maps[counter])
        except IndexError:
           break
        counter += 1

plt.tight_layout()
plt.show()



In [ ]: