emily20
emily20

Reputation: 13

Get Access to colormap "jet"

I need to get access to the pre defined color map "jet". I found my an example to get access to the map "vidiris"

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
viridis = cm.get_cmap('viridis', 12)
print('viridis.colors', viridis.colors)

This gives me the first 12 rows of the map, but i can't get access to the map "jet"

Upvotes: 0

Views: 4552

Answers (1)

JohanC
JohanC

Reputation: 80509

The jet colormap is a LinearSegmentedColormap which doesn't have the .colors attribute. The following approach gets 12 equally spaced colors from the jet colormap:

from matplotlib import pyplot as plt
from matplotlib import cm
import numpy as np

jet = cm.get_cmap('jet')
jet_12_colors = jet(np.linspace(0, 1, 12))
print('jet.colors', jet_12_colors)

viridis = cm.get_cmap('viridis', 12)
print('viridis.colors', viridis.colors)

plt.scatter(range(12), np.repeat(2, 12), color=jet_12_colors)
plt.scatter(range(12), np.repeat(1, 12), color=viridis.colors)
plt.xticks(range(12))
plt.show()

illustrating plot

Upvotes: 4

Related Questions