Colormap Plots
In this article we’ll be talking about colormap plots. These are used to represent three-dimensional data in 2D. The x and y axes are represented by position in a 2D coordinate system whereas the value of z is represented by a color.
There are several methods we can use to create colormaps. One of them is pcolor. It requires the data to be formatted in a two-dimensional array. We can use the numpy meshgrid method to prepare the data.
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
# Let's create the x and y values.
x = y = np.linspace(0, 10, 100)
# Let's format the data.
X, Y = np.meshgrid(x, y)
# Let's define the values of Z.
Z = np.sin(X) ** 5 + np.cos(Y) * np.cos(X)
# Let's create the color map
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z)
You can add edge colors:
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, edgecolors='r')
You can also use predefined mathplotlib color maps. They are available in mpl.cm. To use one, set the cmap accordingly:
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.bwr)
Here are some examples of other built-in color maps.
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.plasma)
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.inferno)
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.Oranges)
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.winter)
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.twilight)
fig, ax = plt.subplots()
ax.pcolor(X, Y, Z, cmap=mpl.cm.jet)
And there are many more. You can use this link:
https://matplotlib.org/stable/gallery/color/colormap_reference.html
to check them out.