<p>There have been some good and useful suggestions already but let me add a few remarks:</p>

<ol>
<li>The viridis and magma palettes are sequential palettes with multiple hues. Thus, along the scale you increase from very light colors to rather dark colors. Simultaneously the colorfulness is increased and the hue changes from yellow to blue (either via green or via red).</li>
<li>Diverging palettes can be created by combining two sequential palettes. Typically, you join them at the light colors and then let them diverge to different dark colors.</li>
<li>Usually, one uses single-hue sequential palettes that diverge from a neutral light gray to two different dark colors. One should pay attention though that the different "arms" of the palette are balanced with respect to luminance (light-dark) and chroma (colorfuness).</li>
</ol>

<p>Therefore, combining magma and viridis does not work well. You could let them diverge from a similar yellowish color but you would diverge to similar blueish colors. Also with the changing hues it would just become more difficult to judge in which arm of the palette you are.</p>

<p>As mentioned by others, ColorBrewer.org provides good diverging palettes. Moreland's approach is also useful. Yet another general solution is our <code>diverging_hcl()</code> function in the <code>colorspace</code> package. In the accompanying paper at <a href="https://arxiv.org/abs/1903.06490" rel="noreferrer">https://arxiv.org/abs/1903.06490</a> (forthcoming in JSS) the construction principles are described and also how the general HCL-based strategy can approximate numerous palettes from ColorBrewer.org, CARTO, etc.
(Earlier references include our initial work in CSDA  at <a href="http://dx.doi.org/10.1016/j.csda.2008.11.033" rel="noreferrer">http://dx.doi.org/10.1016/j.csda.2008.11.033</a> and further recommendations geared towards meteorology, but applicable beyond, in a BAMS paper at <a href="http://dx.doi.org/10.1175/BAMS-D-13-00155.1" rel="noreferrer">http://dx.doi.org/10.1175/BAMS-D-13-00155.1</a>.)</p>

<p>The advantage of our solution in HCL space (hue-chroma-luminance) is that you can interpret the coordinates relatively easily. It does take some practice but isn't as opaque as other solutions. Also we provide a GUI <code>hclwizard()</code> (see below) that helps understanding the importance of the different coordinates.</p>

<p>Most of the palettes in the question and the other answers can be matched rather closely by <code>diverging_hcl()</code> provided that the two hues (argument <code>h</code>), the maximum chroma (<code>c</code>), and minimal/maximal luminance (<code>l</code>) are chosen appropriately. Furthermore, one may have to tweak the <code>power</code> argument which controls how quickly chroma and luminance are increased, respectively. Typically, chroma is added rather quickly (<code>power[1] &lt; 1</code>) whereas luminance is increased more slowly (<code>power[2] &gt; 1</code>).</p>

<p>Moreland's "cool-warm" palette for example uses a blue (<code>h = 250</code>) and red (<code>h = 10</code>) hue but with a relatively small luminance contrast(<code>l = 37</code> vs. <code>l = 88</code>):</p>

<pre><code>coolwarm_hcl &lt;- colorspace::diverging_hcl(11,
  h = c(250, 10), c = 100, l = c(37, 88), power = c(0.7, 1.7))
</code></pre>

<p>which looks rather similar (see below) to:</p>

<pre><code>coolwarm &lt;- Rgnuplot:::GpdivergingColormap(seq(0, 1, length.out = 11),
  rgb1 = colorspace::sRGB( 0.230, 0.299, 0.754),
  rgb2 = colorspace::sRGB( 0.706, 0.016, 0.150),
  outColorspace = "sRGB")
coolwarm[coolwarm &gt; 1] &lt;- 1
coolwarm &lt;- rgb(coolwarm[, 1], coolwarm[, 2], coolwarm[, 3])
</code></pre>

<p>In contrast, ColorBrewer.org's BrBG palette a much higher luminance contrast (<code>l = 20</code> vs. <code>l = 95</code>):</p>

<pre><code>brbg &lt;- rev(RColorBrewer::brewer.pal(11, "BrBG"))
brbg_hcl &lt;- colorspace::diverging_hcl(11,
  h = c(180, 50), c = 80, l = c(20, 95), power = c(0.7, 1.3))
</code></pre>

<p>The resulting palettes are compared below with the HCL-based version below the original. You see that these are not identical but rather close. On the right-hand side I've also matched viridis and plasma with HCL-based palettes.</p>

<p><a href="https://i.stack.imgur.com/nxSiv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nxSiv.png" alt="palettes"></a></p>

<p>Whether you prefer the cool-warm or BrBG palette may depend on your personal taste but also - more importantly - what you want to bring out in your visualization. The low luminance contrast in cool-warm will be more useful if the <em>sign</em> of the deviation matters most. A high luminance contrast will be more useful if you want to bring out the <em>size</em> of the (extreme) deviations. More practical guidance is provided in the papers above.</p>

<p>The rest of the replication code for the figure above is:</p>

<pre><code>viridis &lt;- viridis::viridis(11)
viridis_hcl &lt;- colorspace::sequential_hcl(11,
  h = c(300, 75), c = c(35, 95), l = c(15, 90), power = c(0.8, 1.2))

plasma &lt;- viridis::plasma(11)
plasma_hcl &lt;- colorspace::sequential_hcl(11,
  h = c(-100, 100), c = c(60, 100), l = c(15, 95), power = c(2, 0.9))

pal &lt;- function(col, border = "transparent") {
  n &lt;- length(col)
  plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1),
    axes = FALSE, xlab = "", ylab = "")
  rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border)
}

par(mar = rep(0, 4), mfrow = c(4, 2))
pal(coolwarm)
pal(viridis)
pal(coolwarm_hcl)
pal(viridis_hcl)
pal(brbg)
pal(plasma)
pal(brbg_hcl)
pal(plasma_hcl)
</code></pre>

<p><strong>Update:</strong> These HCL-based approximations of colors from other tools (ColorBrewer.org, viridis, scico, CARTO, ...) are now also available as named palettes in both the <code>colorspace</code> package and the <code>hcl.colors()</code> function from the basic <code>grDevices</code> package (starting from 3.6.0). Thus, you can now also say easily:</p>

<pre><code>colorspace::sequential_hcl(11, "viridis")
grDevices::hcl.colors(11, "viridis")
</code></pre>

<p>Finally, you can explore our proposed colors interactively in a shiny app:
<a href="http://hclwizard.org:64230/hclwizard/" rel="noreferrer">http://hclwizard.org:64230/hclwizard/</a>. For users of R, you can also start the shiny app locally on your computer (which runs somewhat faster than from our server) or you can run a Tcl/Tk version of it (which is even faster):</p>

<pre><code>colorspace::hclwizard(gui = "shiny")
colorspace::hclwizard(gui = "tcltk")
</code></pre>

<p>If you want to understand what the paths of the palettes look like in RGB and HCL coordinates, the <code>colorspace::specplot()</code> is useful. See for example <code>colorspace::specplot(coolwarm)</code>.</p>
What is a "good" palette for divergent colors in R? (or: can viridis and magma be combined together?)
<p>I am interested in having a "good" divergent color pallette. One could obviously use just red, white, and blue:</p>

<pre><code>img &lt;- function(obj, nam) {
  image(1:length(obj), 1, as.matrix(1:length(obj)), col=obj, 
        main = nam, ylab = "", xaxt = "n", yaxt = "n",  bty = "n")
}
rwb &lt;- colorRampPalette(colors = c("red", "white", "blue"))
img(rwb(100), "red-white-blue")
</code></pre>

<p><a href="https://i.stack.imgur.com/eHrwm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eHrwm.png" alt="enter image description here"></a></p>

<p>Since I recently fell in love with the <a href="https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html" rel="noreferrer">viridis color palettes</a>, I was hoping to combine viridis and magma to form such divergent colors (of course, color blind people would only see the absolute value of the color, but that is sometimes o.k.).</p>

<p>When I tried combining viridis and magma, I found that they don't "end" (or "start") at the same place, so I get something like this (I'm using R, but this would probably be the same for python users):</p>

<pre><code>library(viridis)
img(c(rev(viridis(100, begin = 0)), magma(100, begin = 0)), "magma-viridis")
</code></pre>

<p><a href="https://i.stack.imgur.com/255WC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/255WC.png" alt="enter image description here"></a></p>

<p>We can see that when close to zero, viridis is purple, while magma is black. I would like for both of them to start in (more or less) the same spot, so I tried using 0.3 as a starting point:</p>

<pre><code>img(c(rev(viridis(100, begin = 0.3)), magma(100, begin = 0.3)), "-viridis-magma(0.3)")
</code></pre>

<p><a href="https://i.stack.imgur.com/9FJyY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9FJyY.png" alt="enter image description here"></a></p>

<p>This is indeed better, but I wonder if there is a better solution. </p>

<p>(I am also "tagging" python users, since viridis is originally from <code>matplotlib</code>, so someone using it may know of such a solution)</p>

<p>Thanks!</p>