I am looking for a way to get an elevation appropriate colormap for matplotlib
.
the cmap 'terrain
' looks great but the colorscaling isn't based around zero (i.e. if the scale is 0->5000m, the 0->1000m range may be shades of blue, which you would assume to be for below sea-level)
The Matlab function equivalent is:
demcmap
What is the best way to get matplotlib to shift a terrain colormap's greens/browns and blues around the zero elevation mark?
Unfortunaly, matplotlib does not provide the functionality of Matlab's
demcmap
. There might actually be some build-in features in the pythonbasemap
package, of which I'm not aware.So, sticking to matplotlib on-board options, we can subclass
Normalize
to build a color normalization centered around a point in the middle of the colormap. This technique can be found in another question on StackOverflow and adapted to the specific needs, namely to set asealevel
(which is probably best chosen as0
) and the value in the colormapcol_val
(ranging between 0 and 1) to which this sealevel should correspond. In the case of the terrain map, it seems that0.22
, corresponding to a turqoise color, might be a good choice.The Normalize instance can then be given as an argument to
imshow
. The resulting figures can be seen down below in the first row of the picture.Due to the smooth transition around the sealevel the values around
0
appear in a turqoise color, making it hard to distinguish between land and sea.We can therefore change the terrain map a bit and cut out those colors, such that the coastline is better visible. This is done by combining two parts of the map, ranging from 0 to 0.17 and from 0.25 to 1, and thus cutting out a part of it.