Show Matplotlib colormaps
1 from pylab import *
2 from numpy import outer
3 rc('text', usetex=False)
4 a=outer(arange(0,1,0.01),ones(10))
5 figure(figsize=(10,5))
6 subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99)
7 maps=[m for m in cm.datad if not m.endswith("_r")]
8 maps.sort()
9 l=len(maps)+1
10 for i, m in enumerate(maps):
11 subplot(1,l,i+1)
12 axis("off")
13 imshow(a,aspect='auto',cmap=get_cmap(m),origin="lower")
14 title(m,rotation=90,fontsize=10)
15 savefig("colormaps.png",dpi=100,facecolor='gray')
But, what if I think those colormaps are ugly? Well, just make your own using matplotlib.colors.LinearSegmentedColormap.
First, create a script that will map the range (0,1) to values in the RGB spectrum. In this dictionary, you will have a series of tuples for each color 'red', 'green', and 'blue'. The first elements in each of these color series needs to be ordered from 0 to 1, with arbitrary spacing inbetween. Now, consider (0.5, 1.0, 0.7) in the 'red' series below. This tuple says that at 0.5 in the range from (0,1) , interpolate from below to 1.0, and above from 0.7. Often, the second two values in each tuple will be the same, but using diferent values is helpful for putting breaks in your colormap. This is easier understand than might sound, as demonstrated by this simple script:
1 from pylab import *
2 cdict = {'red': ((0.0, 0.0, 0.0),
3 (0.5, 1.0, 0.7),
4 (1.0, 1.0, 1.0)),
5 'green': ((0.0, 0.0, 0.0),
6 (0.5, 1.0, 0.0),
7 (1.0, 1.0, 1.0)),
8 'blue': ((0.0, 0.0, 0.0),
9 (0.5, 1.0, 0.0),
10 (1.0, 0.5, 1.0))}
11 my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256)
12 pcolor(rand(10,10),cmap=my_cmap)
13 colorbar()
As you see, the colormap has a break halfway through. Please use this new power responsibly.

