# Wrong labelling of contours with ListContourPlot

Bug introduced in 8 or earlier and persisting through 11.0.1 or later

Consider this example:

dat = Table[Re[Sqrt[1 - x^2 - y^2]], {x, -1.1, 1.1, 0.01}, {y, -1.1, 1.1, 0.01}];


Now pay special attention to the labelling of contours.

Here everything looks good:

ListContourPlot[dat, Contours -> {1., 0.9, 0.8, 0.7, 0.6, 0.5}, ContourLabels -> All]


But look!

ListContourPlot[dat, Contours -> Range[1, 0.5, -0.1], ContourLabels -> All]


The labelling of contours is now wrong: it is inverted. The largest one gets the smallest label.

As far as I can tell, the two ListContourPlot commands are completely equivalent. One has a Range, the second one has what the Range would evaluate to.

Range[1, 0.5, -0.1]
(* {1., 0.9, 0.8, 0.7, 0.6, 0.5} *)


ListContourPlot is not HoldAll.

Attributes[ListContourPlot]


I must be missing something obvious, but it's late here and I'm tired and I cannot see what. I'm using M10.4 on OS X.

Update: I solved the mystery: the difference between Range[1, 0.5, -0.1] and {1., 0.9, 0.8, 0.7, 0.6, 0.5} is that the former is a packed array. It seems this is just a plain old bug...

• Given your discovery, a workaround -- other than avoiding use of Range -- would be ListContourPlot[dat, Contours -> (# & /@ Range[1, 0.5, -0.1]), ContourLabels -> All] – Bob Hanlon Mar 12 '16 at 0:51
• @BobHanlon. Turns out the incredibly silly-looking List@@Range[1, 0.5, -0.1] fixes it too. – march Mar 12 '16 at 4:45
• You should add bug Tag to the question. – Algohi Mar 12 '16 at 5:16
• @Algohi I think it's better if you do that yourself. The idea is that it should be someone else than the original poster who adds it. I don't want to show a bad example. – Szabolcs Mar 13 '16 at 10:17

The reason for the difference between the outputs is that Range[1,0.5,-0.1] is a packed array while {1., 0.9, 0.8, 0.7, 0.6, 0.5} is not.

If the Contours specification is a packed array, the output will be incorrect.

DeveloperFromPackedArray@Range[...] can be used as a workaround.

When being an option of Interpolation, ListInterpolation, FunctionInterpolation, using packed array as the option value of InterpolationOrder also causes problem:

f = Interpolation[{1, 2, 3, 5, 8, 5}, InterpolationOrder ->{3}]
(* Works as expected *)
f = Interpolation[{1, 2, 3, 5, 8, 5}, InterpolationOrder -> DeveloperToPackedArray@{3}]


• that is just bizarre. – rcollyer Mar 14 '16 at 14:35
• Also, if the contours are in ascending order, it works fine. – rcollyer Mar 14 '16 at 14:45