# Getting unexpected coloring behavior when labelling a subset of contours in ListContourPlot

I wanted to adopt this procedure to label only specific countourlines in this ContourPlot. The only difference is that the lowest value is not zero and I added a colorfunction.

data = Table[{m/100, n/100, 2 + (m^2 + n^2)/20000}, {m, 0, 100}, {n, 0, 100}];
data = Flatten[data, 1];
contour = Range[2, 3, 0.05];
contourplot =
ListContourPlot[data,
Axes -> True,
ColorFunction ->ColorData["BlueGreenYellow"],
Contours -> contour,
PlotRange -> {2, 3},
PlotLegends -> Automatic]


However, I noticed that the range of the Colorfunction is changed, when the lowest value in my plot is not 0, Consider,

contourplot =
ListContourPlot[data,
Axes -> True,
ColorFunction -> ColorData["BlueGreenYellow"],
Contours -> contour,
PlotRange -> {2, 3},
ContourLabels ->
(If[MemberQ[{2.25, 2.5, 2.75}, #3],
Text[Framed[#3], {#1, #2}, Background -> White]] &),
PlotLegend->Automatic]


I only wanted to add ContourLabels without changing the color at all. I would be thankful for any advice/workaround, because I don't know what might cause this error.

I finally found the answer: Both functions, BarLegend and Colorfunction need to be rescaled, by adding a range:

data = Table[{m/100, n/100, 2 + (m^2 + n^2)/20000}, {m, 0, 100}, {n, 0, 100}];
data = Flatten[data, 1];
contour = Range[2, 3, 0.05];
contourplot =
ListContourPlot[data,
Axes -> True,
ColorFunction -> (ColorData["BlueGreenYellow"][Rescale[#1, {2, 3}]] &),
ColorFunctionScaling -> False,
Contours -> contour,
ContourLabels ->
(If[MemberQ[{2.25, 2.5, 2.75}, #3],
Text[Framed[#3], {#1, #2}, Background -> White]] &),
PlotLegends -> BarLegend[{Automatic, {2, 3}}]]


• You shouldn't have to do this, what version of Mathematica are you using? Jul 30, 2016 at 1:21
• 10.2 (student version) Aug 1, 2016 at 10:42