I am searching for a color combination option that starts with whitish and ends with red, and in between more colors. In Matplotlib colormaps option I searched but didn't get that. Any way to do the same?
CodePudding user response:
You could create a custom colormap from white and the color of 'jet'.
Here is an example:
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.cm import ScalarMappable
import numpy as np
fig, ax = plt.subplots(figsize=(12, 1))
fig.subplots_adjust(bottom=0.4)
cmap_jet = plt.get_cmap('jet')
cmap = LinearSegmentedColormap.from_list('', ['white'] list(cmap_jet(np.linspace(0, 1, 7))))
plt.colorbar(ScalarMappable(cmap=cmap, norm=plt.Normalize(1, 2.5)), cax=ax,
orientation='horizontal', ticks=np.arange(1, 2.5001, .3))
plt.show()
To get a wider range between white and the start of the jet colormap, you could provide a list of tuples to LinearSegmentedColormap
:
blue_start = 0.3
color_list = [(0, 'white')] list( zip(np.linspace(blue_start, 1, 10), cmap_jet(np.linspace(0, 1, 10))))
cmap = LinearSegmentedColormap.from_list('', color_list)