Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for a colormap with similarities to CMRmap

I'm looking for the following colormap in matplotlib, which I saw in a paper: enter image description here

At first I thought it was a section of the CMRmap colormap.

cmap = plt.get_cmap('CMRmap')
new_cmap = truncate_colormap(cmap, 0.0, 0.75) #(https://stackoverflow.com/a/18926541/7559986)

However, the following came out when I extract a subset of it, which looks a bit different (especially the yellow):

enter image description here

Does anyone know how I get to the upper colormap?

like image 466
Anne Bierhoff Avatar asked Oct 17 '25 11:10

Anne Bierhoff


1 Answers

The colormap you show looks like it's just an interpolation between black, blue, red and yellow. This would be created via

matplotlib.colors.LinearSegmentedColormap.from_list("", ["black", "blue", "red", "yellow"])

However, I would not recommend using such colormap. Instead use any of "viridis", "magma", "plasma" or "inferno". Those are perceptually uniform and hence do not create unwanted artifacts.

Below is a comparisson between the interpolated map and "magma". As you can see the interpolated map creates "rings", such that the viewer would surely misinterprete the shape that is plotted.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors

x = np.linspace(-2,2, 101)
X,Y = np.meshgrid(x,x)
Z = np.exp(-X**2-Y**2)

fig, (ax1, ax2) = plt.subplots(ncols=2)

im1 = ax1.imshow(Z, cmap="magma")


cmap = mcolors.LinearSegmentedColormap.from_list("", ["black", "blue", "red", "yellow"])
im2 = ax2.imshow(Z, cmap=cmap)

fig.colorbar(im1, ax=ax1, orientation="horizontal")
fig.colorbar(im2, ax=ax2, orientation="horizontal")

plt.show()

enter image description here

Further reading

  • https://matplotlib.org/3.1.1/tutorials/colors/colormaps.html
  • https://bids.github.io/colormap/ on why it's bad to use such non-uniform maps.
like image 132
ImportanceOfBeingErnest Avatar answered Oct 19 '25 01:10

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!