Colour bar for contour 2D graph [duplicate]

This question already has an answer here:

Plotting legends in contourplot

1 answer

How could I plot the colour legend for my 2D contour graph

ListContourPlot[
arrayData,
ColorFunction -> ColorData[“Rainbow”],
ContourStyle -> None,
FrameLabel -> {“Rs”, “Rd”},
GridLines -> Automatic, PlotRange -> Automatic
]

=================

=================

2 Answers
2

=================

This is how you add a color legend to your ListContourPlot (also true for similar types of plots). This is by the way the third example in the ListContourPlot documentation. Of course, the crucial part is the PlotLegends option.

data = Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}], Sin[x y]}, 1000}];
ListContourPlot[
data,
ColorFunction -> ColorData[“Rainbow”],
ContourStyle -> None,
FrameLabel -> {“Rs”, “Rd”},
PlotLegends -> Automatic]

If you are using Mathematica version 9.0 or later, you can use the PlotLegends option as shown in the documentation and in Lukas’s answer (beat me to it by 2 minutes).

But if you are using an older version you have to resort to the PlotLegends package (I know it’s confusing),

<< PlotLegends` With[{arrayData = Array[Sin[.01 Ï€ (#1 - 2 #2)] &, {100, 100}]}, ShowLegend[ ListContourPlot[arrayData, ColorFunction -> ColorData[“Rainbow”],
ContourStyle -> None,
FrameLabel -> {“Rs”, “Rd”},
GridLines -> Automatic,
PlotRange -> Automatic],
{ColorData[“Rainbow”][1 – #1] &, 10, ” 1″, “-1”,
LegendPosition -> {1.1, -0.4}}]
]