1
$\begingroup$

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
]
$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Apr 22 '16 at 6:07
  • $\begingroup$ Please publish (at least a small part of) your arrayData. Otherwise we cannot try and see, how we can help you. $\endgroup$ – Alexei Boulbitch Apr 22 '16 at 7:44
3
$\begingroup$

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]

enter image description here

$\endgroup$
2
$\begingroup$

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

enter image description here

$\endgroup$

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