3
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ Look up Blend and ColorFunction. $\endgroup$
    – Szabolcs
    Jun 13, 2022 at 8:38

2 Answers 2

7
$\begingroup$

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}]

seismic colormap

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]

contour plot of MATLAB's "peaks"

$\endgroup$
3
$\begingroup$

After some trial and error:

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

LinearGradientImage[Function[x, seismic[x]], {300, 30}]

As an example:

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.