# Labelling a subset of contours using ListContourPlot

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]

• possible duplicate of Custom contour labels in ContourPlot
– Jens
Nov 14, 2014 at 18:35
• An answer in the proposed duplicate mentions the placement of the labels may require that you solve for the root (contour-value) of your expression; might this be a problem for the OP's data, which is plotted with ListContourPlot? Nov 14, 2014 at 21:14

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]] &)] • That was fast! That works perfectly, thanks very much! Nov 14, 2014 at 14:49
• @n-ism, my pleasure. Thank you for the accept... And welcome to mma.se.
– kglr
Nov 14, 2014 at 17:10

Quick fix:

contourplot /. x : {__Text} :> x[[;; ;; 2]] • 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. Nov 14, 2014 at 14:56