Color maps in Matplotlib and creating own color bar

Color maps are important to clarify the scientific plots better. Better color bar can help to make interesting and self explanatory Graph and Maps.

For python/ipython module, Matplotlib offers a long list of sequential to diverging colormaps. We can change the colormap in previous example as:

csf = map.contourf(x,y,a,clevsf,extend='both',cmap='coolwarm')
# filled contour

“coolwarm” is a diverging colormap that is useful to show positive and negative data points in a graph (i.e. anomalies).

Divergent colormaps

For list of colormaps in Matplotlib follow this link

If we want to make a specific color map for our plot which is not available in Matplotlib list, we will need to install colormap and easydev python package package. For installing package in anaconda follow this link. Alternatively, we can also install the package using pip as:

pip install colormap
pip install easydev

For example if we want to make a sequential gradient colormap that will start from white to blue and end with dark blue,

from colormap import Colormap
c = Colormap()
cmap = c.cmap_linear('white','SkyBlue','royalblue')

Now test the colormap by typing: cmap = c.test_colormap(cmap)

We should get a test map like this:

Now we can use this color map for our plot as before in Matplotlib plot, except we don’t have to use the quote in syntax

csf = map.contourf(x,y,a,clevsf,extend='both',cmap=cmap)
# cmap using colormap that we just made.

List of color that colormap module use attached in the color.txt file. We can try different combination of colors to make customized colormap.

For more details about customized colormap and colormap module follow this link.