Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Consider this example below for ListContourPlot.

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

ListContourPlot[
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.

share|improve this question
    
Which version are you using? –  Mr.Wizard Apr 27 '13 at 7:19
    
Version Number : 9.0.0.0 –  Hubble07 Apr 27 '13 at 7:23
    
@Pinguin Dirk : i hav edited my question ,pls hav a look at it. –  Hubble07 Apr 27 '13 at 9:24
    
ok, @swish's answer kind of opens my eyes what you want (why is another question :) ), sorry for being so complicated –  Pinguin Dirk Apr 27 '13 at 10:22
    
@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. –  Hubble07 Apr 27 '13 at 11:09
add comment

1 Answer

up vote 6 down vote accepted

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

share|improve this answer
    
Yes this(SwatchLegend) is what i was looking for,Merci. –  Hubble07 Apr 27 '13 at 10:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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