Skip to content

Instantly share code, notes, and snippets.

@etherealmachine
Created July 12, 2011 20:44
Show Gist options
  • Save etherealmachine/1078939 to your computer and use it in GitHub Desktop.
Save etherealmachine/1078939 to your computer and use it in GitHub Desktop.
Heatmap with contour lines using matplotlib
import numpy as np
import numpy.random
import matplotlib.pyplot as plt
def f(x, y):
return x*y
xmax = ymax = 100
z = numpy.array([[f(x, y) for x in range(xmax)] for y in range(ymax)])
plt.pcolormesh(z)
plt.colorbar()
curves = 10
m = max([max(row) for row in z])
levels = numpy.arange(0, m, (1 / float(curves)) * m)
plt.contour(z, colors="white", levels=levels)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment