All pastes #1511403 Raw Edit

Random colormaps with matplotlib

public python v1 · immutable
#1511403 ·published 2009-07-29 19:40 UTC
rendered paste body
import matplotlib,numpyimport pylab#Generate some example data... From http://matplotlib.sourceforge.net/examples/pylab_examples/contourf_demo.htmldelta = 0.025x = numpy.arange(-3.0, 3.0, delta)y = numpy.arange(-2.0, 2.0, delta)X, Y = numpy.meshgrid(x, y)Z1 = pylab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)Z2 = pylab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)# difference of GaussiansZ = 100.0 * (Z2 - Z1)#This is the random colormap bitrandom_colormap = matplotlib.colors.ListedColormap ( numpy.random.rand ( 10,3))#Does it work?pylab.imshow ( Z, cmap = random_colormap)pylab.colorbar()pylab.show()