6

I have a data set with entries of the form [nx,ny,E] and have made a contour plot of this data. I would like to add labels to only a subset of these contours, for instance every other contour. How might I go about doing that?

My data set is derived from a calculation, and so my data points are not samples of a function with two arguments. I have made an example code below:

data = Table[{m/100, n/100, (m^2 + n^2)/20000}, {m, 0, 100}, {n, 0, 100}];
data = Flatten[data, 1];
contour = Range[0, 1, 0.05];
contourplot = ListContourPlot[data, Axes -> True, Contours -> contour, ContourLabels -> All, ContourShading -> None]
Kuba
  • 136,707
  • 13
  • 279
  • 740
n-ism
  • 63
  • 3

2 Answers2

5
data = Table[{m/100, n/100, (m^2 + n^2)/20000}, {m, 0, 100}, {n, 0,  100}];
data = Flatten[data, 1];
contour = Range[0, 1, 0.05];

lbldcont = Range[0, 1, 0.05][[{1, 3, 5, 12, 15, 20}]]; 
(* {0., 0.1, 0.2, 0.55, 0.7, 0.95} *)

ListContourPlot[data, Axes -> True, Contours -> Range[0, 1, 0.05], ContourShading -> None,
 ContourLabels -> (If[MemberQ[lbldcont, #3],Text[#3, {#1, #2}, Background -> Transparent]] &)]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
4

Quick fix:

contourplot /. x : {__Text} :> x[[;; ;; 2]]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • Thanks for this solution! I tried using it on my original notebook and found that it did not remove every other contour label like it did with the example I gave. The labels it did remove did make the plot more legible though. – n-ism Nov 14 '14 at 14:56