import cppcolormap as cm import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np cmap = cm.Reds() m_cmap = mpl.colors.ListedColormap(cmap, name="Reds", N=cmap.shape[0]) xterm = cm.xterm() idx = cm.match(cmap, xterm, cm.metric.perceptual) m_xterm = mpl.colors.ListedColormap(xterm[idx, :], name="xterm", N=cmap.shape[0]) fig, axes = plt.subplots(figsize=(16, 8), ncols=2) x, y = np.meshgrid(np.linspace(0, 99, 100), np.linspace(0, 99, 100)) z = (x - 50)**2.0 + (y - 50)**2.0 im = axes[0].imshow(z, cmap=m_cmap, clim=(0, 5000)) im = axes[1].imshow(z, cmap=m_xterm, clim=(0, 5000)) plt.savefig("match.pdf") plt.close()
import cppcolormap as cmap import matplotlib.pyplot as plt import numpy as np colormapNames = 'Accent,Dark2,Paired,Spectral,Pastel1,Pastel2,Set1,Set2,Set3,Blues,Greens,Greys,Oranges,Purples,Reds,BuPu,GnBu,PuBu,PuBuGn,PuRd,RdPu,OrRd,RdOrYl,YlGn,YlGnBu,YlOrRd,BrBG,PuOr,RdBu,RdGy,RdYlBu,RdYlGn,PiYG,PRGn' # number of colors in the colormap (optional, may be omitted) N = 128 # specify the colormap as string cr = cmap.colormap("Reds", N) cc = cmap.colorcycle("tue") # or call the functions directly c = cmap.Reds(N) c = cmap.tue() plt.imshow( np.reshape( cmap.colormap(colormapNames.split(',')[6], N * N) / 255., (N, N, 3))) plt.show()