Consider this example below for ListContourPlot.

  Table[Sin[j^2 + i], {i, 0, Pi, 0.02}, {j, 0, Pi, 0.02}], 
  PlotLegends -> Automatic]

I wish to make the Legend look like this:

enter image description here

I have searched the net but did not find any way of doing this. I'm sure this can be done because that legend in the link is created using Mathematica but I can't figure out how.

Maybe it's something very trivial but I would really appreciate if someone could help me with this because I always had a hard time dealing with legends in Mathematica.

The example that I gave above was just for illustration. My actual function is more like this:-

Table[Cos[Sqrt[bx^2 + by^2]], {bx, -1, 1, 0.1}, {by, -1, 1, 0.1}], 
ContourLabels -> All, ColorFunction -> "Rainbow", 
  PlotLegends -> BarLegend[Automatic, All]]

So the plot looks like this:-

enter image description here

This legend has clear color bands which can be separated like that shown in the legend above.

So my question is whatever may be the case can we make a legend that looks like the one I showed.

  • $\begingroup$ Which version are you using? $\endgroup$
    – Mr.Wizard
    Apr 27, 2013 at 7:19
  • $\begingroup$ Version Number : $\endgroup$
    – Hubble07
    Apr 27, 2013 at 7:23
  • $\begingroup$ @Pinguin Dirk : i hav edited my question ,pls hav a look at it. $\endgroup$
    – Hubble07
    Apr 27, 2013 at 9:24
  • $\begingroup$ ok, @swish's answer kind of opens my eyes what you want (why is another question :) ), sorry for being so complicated $\endgroup$ Apr 27, 2013 at 10:22
  • $\begingroup$ @PD Just remembered this quote “Science answers the ‘how’ question. The ‘why’ question is just a silly question. The question is an inappropriate one.” -Richard Dawkins. Anyways thank you for ur time & effort. $\endgroup$
    – Hubble07
    Apr 27, 2013 at 11:09

1 Answer 1


I'm sure you can move from here and make the legend you desire.

(*Make your plot*)    
plot = ListContourPlot[
   Table[Cos[Sqrt[bx^2 + by^2]], {bx, -1, 1, 0.1}, {by, -1, 1, 0.1}], 
   ContourLabels -> All, ColorFunction -> "LakeColors"];

(*Specify your legend labels*)
labels = Range[0.1, 1, 0.1];

(*Make legend*)    
legend = SwatchLegend["LakeColors", labels, 
   LegendMarkerSize -> {{15, 15}}, LabelStyle -> {Italic, 12}];

(*Combine them together*)
Legended[plot, legend]

enter image description here

  • $\begingroup$ Yes this(SwatchLegend) is what i was looking for,Merci. $\endgroup$
    – Hubble07
    Apr 27, 2013 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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