Colormaps

Colormaps map numerical values to a range of colors.

Since Matplotlib 2.0, the default colormap has been changed from 'jet', which spans the visible light spectrum from red to blue, to 'viridis', which is a perceptually uniform continuum from yellow to blue. This makes it more intuitive to perceive continuous values:

import numpy as np
import matplotlib.pyplot as plt

N = M = 200
X, Y = np.ogrid[0:20:N*1j, 0:20:M*10]
data = np.sin(np.pi * X*2 / 20) * np.cos(np.pi * Y*2 / 20)

fig, (ax2, ax1) = plt.subplots(1, 2, figsize=(7, 3)) # cmap=viridis by default
im = ax1.imshow(data, extent=[0, 200, 0, 200])
ax1.set_title("v2.0: 'viridis'")
fig.colorbar(im, ax=ax1, shrink=0.85)

im2 = ax2.imshow(data, extent=[0, 200, 0, 200], cmap='jet')
fig.colorbar(im2, ax=ax2, shrink=0.85)
ax2.set_title("classic: 'jet'")

fig.tight_layout()
plt.show()

Check out the following image generated with the preceding code to understand what perceptual color uniformity means:

Matplotlib also provides a number of preset colormaps that are optimized for displaying diverging values or qualitative categories. Feel free to check them out at: https://matplotlib.org/2.1.0/tutorials/colors/colormaps.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.42.205