April 2018
Beginner to intermediate
300 pages
7h 34m
English
We can set up our own colormap. This is useful when customizing heatmaps and surface plots. A simple way to create a custom linear colormap is to prepare a list of colors and allow Matplotlib to handle the transition. Let's look at the following example:
import numpy as npimport matplotlib.pyplot as pltimport matplotlib.colors# Create a 30 random dotsnp.random.seed(52)x,y,c = zip(*np.random.rand(30,3))# Create a custom linear colormapcmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","yellow","green"])
plt.scatter(x,y,c=c, cmap=cmap)plt.colorbar()plt.show()
Here, we have a scatter plot with a colormap set up on our own, morphing from red through yellow to green:
Read now
Unlock full access