Reputation: 337
I would like a diverging colormap that has another colour than white (preferably black) as it center color. Neither matplotlib or cmocean seems to have such a colormap. Is my best option to create an own colormap, or are there existing ones?
Upvotes: 10
Views: 4654
Reputation: 198
If you don't want to use other libraries, you can do something like this:
from matplotlib.colors import LinearSegmentedColormap
color_min = "#4203ff"
color_center = "black"
color_max = "#ff0342"
cmap = LinearSegmentedColormap.from_list(
"cmap_name",
[color_min, color_center, color_max]
)
Thanks to this user for the answer.
Upvotes: 2
Reputation: 51
@JohanC put an obvious answer in their comment and I didn't see it because of the accepted answer which requires a less-known package:
Seaborn supports arbitrary diverging palettes with black center
hue_neg, hue_pos = 250, 15
cmap = sns.diverging_palette(hue_neg, hue_pos, center="dark", as_cmap=True)
Upvotes: 1