4
$\begingroup$

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

enter image description here

$\endgroup$
2
  • $\begingroup$ If neither ColorData["RedBlueTones"] nor ColorData["ThermometerColors"] suit your needs, you might want to mention first where you got that color gradient from. $\endgroup$
    – J. M.'s torpor
    Feb 27 at 20:52
  • $\begingroup$ @J.M., I am aware of Mathematica color schemes, and the color scheme I posted I think it is one of matplotlib schemes. $\endgroup$ Feb 27 at 21:12
7
$\begingroup$
img = Import["https://i.stack.imgur.com/lSxA8.png"];

Get the colors from img:

dc = DominantColors[img]

enter image description here

Manually sort them as desired:

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

enter image description here

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]

enter image description here

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

enter image description here

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

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, #] &];

LinearGradientImage[RdBuMap, {600, 60}]

RdBu color gradient

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

legend with RdBu colormap


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, #] &];

LinearGradientImage[CoolWarmMap, {600, 60}]

coolwarm color gradient

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

legend with coolwarm colormap

$\endgroup$
1
  • 1
    $\begingroup$ thanks for the precise and detailed answer, @J. M. $\endgroup$ Feb 27 at 22:50

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