Home > Software design >  Choosing Colormaps in Matplotlib: bit confusing
Choosing Colormaps in Matplotlib: bit confusing

Time:12-09

I am searching for an color combination option that starts with whitish and end with red, and in between more sequencing colors. in matplotlib colormaps option I searched the same but didn't get that. Any way to do the same!!

Example colorbar

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()

custom colormap white jet

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)

longer range between white and blue

  • Related