# How do I produce a BarLegend with the default coloring of a ContourPlot, using Legended?

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


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

• For reference: Sort[DataPacletsColorDataDumpgradientSchemeNames] gives a complete list of all the available gradients. Commented Jun 9, 2016 at 7:26

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


I found the name of the color scheme by evaluating

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


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

• Added some code to round out the example. Commented Apr 30, 2015 at 14:10
• Thanks, the edits definitely improve the answer. Commented Apr 30, 2015 at 14:12
• The answer already got a +1 from me. I was just rounding it out. Commented Apr 30, 2015 at 14:18
• Thanks for figuring this out! +1 Commented May 1, 2015 at 8:18

Create your plots with the option PlotLegends -> Automatic:

threecontourplots = {plot1, plot2, plot3} =
ContourPlot[#, {x, 0, 1}, {y, 0, 1}, PlotLegends -> Automatic, ImageSize -> 300] & /@
{x y, x + y , x};


For a legended plot object plot, you can use Part to extract the main plot (plot1[[1]]) and the legend (plot1[[2,1]]).

threecontourplots[[1, 2, 1]]


You can use the extracted parts with Row, GraphicsRow, Grid,GraphicsGrid as well as with Legended:

Row[Append[threecontourplots[[1, 2, 1]]]@threecontourplots[[All, 1]],
Spacer[10]]


Legended[Row[threecontourplots[[All, 1]], Spacer[10]],
Placed[threecontourplots[[1, 2, 1]], Right]]


If you use a non-default color function in ContourPlot (say, ColorFunction -> "Rainbow") no modification will be needed: