7
$\begingroup$

I have a series of ContourPlots that I want to compare in a GraphicsRow environment. I want to add a single legend for all three plots. Also, I really like the standard color scheme of the ContourPlot.

How can I use the standard ColorFunction from ContourPlot in a different Graphics object?

I did not find the ColorFunction that ContourPlot uses inside ColorData["Gradients"].

A minimal working example would be this line

Legended[ContourPlot[x y, {x, 0, 1}, {y, 0, 1}],
         Placed[BarLegend[{Automatic, {0, 1}}, LegendLayout -> "Row"], Below]]

Mathematica graphics

where I'm done when the BarLegend shows the same colors as the ContourPlot.

$\endgroup$
  • $\begingroup$ For reference: Sort[DataPaclets`ColorDataDump`gradientSchemeNames] gives a complete list of all the available gradients. $\endgroup$ – J. M. is in limbo Jun 9 '16 at 7:26
11
$\begingroup$
Legended[ContourPlot[x y, {x, 0, 1}, {y, 0, 1}],
 Placed[BarLegend[{ColorData["M10DefaultDensityGradient"], {0, 1}}, 
   LegendLayout -> "Row"], Below]]

Mathematica graphics

I found the name of the color scheme by evaluating

plot = ContourPlot[x y, {x, 0, 1}, {y, 0, 1}, PlotLegends -> Automatic]

Mathematica graphics

and looking at the expression of the result. As Legended accepts two arguments with the second being the legend, this can be easily done by running

plot[[2]] // InputForm
$\endgroup$
  • $\begingroup$ Added some code to round out the example. $\endgroup$ – rcollyer Apr 30 '15 at 14:10
  • $\begingroup$ Thanks, the edits definitely improve the answer. $\endgroup$ – Gerli Apr 30 '15 at 14:12
  • $\begingroup$ The answer already got a +1 from me. I was just rounding it out. $\endgroup$ – rcollyer Apr 30 '15 at 14:18
  • $\begingroup$ Thanks for figuring this out! +1 $\endgroup$ – Neuneck May 1 '15 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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