This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Friday, November 20, 2015

python colormaps

When creating plots it is very important to consider the kind of colormap you wish to display the data in. Some colormaps will emphasize certain features more than others. But other color schemes may be deceiving, particularly the rainbow color scheme. See an example here.

Utah terrain with
viridis color map in matplotlib 2.0
Note: In Matplolib Version 2 the default colormap is a green shade called 'viridis' which is much better than jet (see here).

Python's matplotlib module has many preloaded colormaps you can use in your figures. You can look at the available colormaps here: http://matplotlib.org/examples/color/colormaps_reference.html, but I find that looking at just the color bars makes it difficult to imagine what a real plot might look like. So...I created a terrain plot for Utah at 3 km resolution with each python colormap to help visualize what each of the plot would look like.

To set your plot with the desired colormap, simply use the argument:
cmap=plt.get_cmap('name_of_colormap')

For example:
plt.pcolormesh(x,y,height,cmap=plt.get_cmap('Accent'))

Below are all the available colormaps in matplotlib. It is possible to create your own more info on creating your own here.

Matplotlib Default Colormaps
 










































































Custom Terrain Colormap
It is possible to create your own colormap (click  here).
A custom terrain colormap created using this custom colormap: here.

Luke's Colormaps
From github https://github.com/lmadaus/old_wrf_plotting_scripts/blob/master/coltbls.py. You'll load these differently than the default colormaps, but the following are the different options you can use...
















No comments:

Post a Comment

Note: Only a member of this blog may post a comment.