How can I create specific color scheme in Mathematica [duplicate]

Is it possible to create a Color Scheme like the one below?

• If neither ColorData["RedBlueTones"] nor ColorData["ThermometerColors"] suit your needs, you might want to mention first where you got that color gradient from. Feb 27 at 20:52
• @J.M., I am aware of Mathematica color schemes, and the color scheme I posted I think it is one of matplotlib schemes. Feb 27 at 21:12

img = Import["https://i.stack.imgur.com/lSxA8.png"];


Get the colors from img:

dc = DominantColors[img]


Manually sort them as desired:

cl = dc[[{5, 3, 6, 1, 7, 4, 2, 8}]]


Use the sorted color list with Blend and use it with BarLegend:

BarLegend[{Blend[cl, Rescale[#, {-2, 2}]] &, {-2, 2}},
LegendMarkerSize -> {50, 300}, LabelStyle -> 16]


(Not exactly the same as the image in your post, but this should give you an idea.)

With additional manual tweaks we can get closer to the reference image:

cf = Blend[{{-2, cl[[1]]}, {-3/2, cl[[2]]}, {-1, cl[[3]]}, {0, White},
{1, cl[[-3]]}, {3/2, cl[[-2]]}, {2, cl[[-1]]}}, #] &;

BarLegend[{cf, {-2, 2}}, LegendMarkerSize -> {50, 300},
LabelStyle -> 16]


• thanks, @kglr, That is AWESOME! now I can create any color schemes I like from other platforms. Feb 27 at 21:14

If you're trying to implement the "RdBu" colormap from Matplotlib (or any other colormap, really), you can always look at the source to extract the colors being used internally, so that you can feed them to Blend[].

In particular,

With[{cols = RGBColor /@ {"#053061", "#2166ac", "#4393c3", "#92c5de",
"#d1e5f0", "#f7f7f7", "#fddbc7", "#f4a582",
"#d6604d", "#b2182b", "#67001f"}},
RdBuMap = Blend[cols, #] &];



BarLegend[{RdBuMap[Rescale[#, {-2, 2}]] &, {-2, 2}}]


As another example, here is the "coolwarm" diverging colormap, also from Matplotlib:

With[{cols = RGBColor /@
{"#3b4cc0", "#445acc", "#4d68d7", "#5775e1", "#6282ea", "#6c8ef1",
"#779af7", "#82a5fb", "#8db0fe", "#98b9ff", "#a3c2ff", "#aec9fd",
"#b8d0f9", "#c2d5f4", "#ccd9ee", "#d5dbe6", "#dddddd", "#e5d8d1",
"#ecd3c5", "#f1ccb9", "#f5c4ad", "#f7bba0", "#f7b194", "#f7a687",
"#f49a7b", "#f18d6f", "#ec7f63", "#e57058", "#de604d", "#d55042",
"#cb3e38", "#c0282f", "#b40426"}},
CoolWarmMap = Blend[cols, #] &];


BarLegend[{CoolWarmMap[Rescale[#, {-2, 2}]] &, {-2, 2}}]