# Use python color scale in mathematica density plot

I have a python code for data analysis, that uses the "seismic" color scale for 2D density plots. However, I also need to do some other plots with Mathematica (because of packages etc), for which I would like the same color scale. Unfortunately, the closer resembling color scale (temperature map) of Mathematica is still quite different from the one in Python. Do you have any suggestion on how to "export/import" a color scale between python and mathematica? This can then be applied to any variation of color map.

• Look up Blend and ColorFunction. Commented Jun 13, 2022 at 8:38

There's no need to guess if you look at the Matplotlib source:

seismicColors[x_?NumericQ] /; 0 <= x <= 1 :=
Blend[{RGBColor[0., 0., 0.3], RGBColor[0., 0., 1.], RGBColor[1., 1., 1.],
RGBColor[1., 0., 0.], RGBColor[0.5, 0., 0.]}, x]


Examples:

LinearGradientImage[seismicColors, {300, 30}]


ContourPlot[3 (1 - x)^2 Exp[-x^2 - (y + 1)^2] - 10 (x/5 - x^3 - y^5) Exp[-x^2 - y^2] -
Exp[-(x + 1)^2 - y^2]/3, {x, -3, 3}, {y, -3, 3},
ColorFunction -> seismicColors, Contours -> 25, PlotRange -> All]


After some trial and error:

seismic[x_] :=
Blend[{Black, Darker@Blue, Blue, White, Red, Darker@Red,
Darker@Darker@Red}, x]


Plot3D[2 Sin[x + Cos[y]], {x, -5, 5}, {y, -5, 5}