# ContourLabels issues

The ContourPlot generated by

k = 1.380648813 10^-23; T1 = 273; T2 = 330;
plt = ContourPlot[.3/(k T) Log10[1 + Z]/Z, {T, T1, T2}, {Z, 1, 50},
PlotRange -> All, ContourLabels -> All, PlotRangePadding -> 10]


(simplified from Question 78999) incorrectly lists the values of several contours as 0.

From

Cases[plt, Text[z_, __] -> z, Infinity]
(* {2500000000000000000, 5000000000000000000, 7500000000000000000, 0, 0, 0, 0, 0, 0} *)


it is evident that ContourPlot is not passing values equal to 10^19 or greater.

Is there any command or simple work-around to alleviate this problem (apart from dividing the first ContourPlot argument by some number rs = 3 or greater and then replacing ContourLabels -> All by ContourLabels -> Function[{x, y, z}, Inset[z*rs, {x, y}]]?

• The cut-off appears to be at Developer\$MaxMachineInteger Apr 4, 2015 at 20:35
• Setting contours explicitly seems to fix it: Contours -> FindDivisions[{0, 2*10^19}, 10] Apr 4, 2015 at 21:10
• @SimonWoods Thanks for your solution. Please consider submitting it as an Answer, even if you do not care about the points, so that it has more visibility. Apr 4, 2015 at 21:37

Labeling the contours in this case requires many digits, but becomes much more readable (I think) if scientific notation is used. To work around the incorrect chopping of the contour labels and also force Mathematica to use scientific notation, I would suggest the following:

plotFunction[T_, Z_] := .3/(k T) Log10[1 + Z]/Z

labelFunction = Text[plotFunction[#1, #2], {#1, #2}] &;

k = 1.380648813 10^-23; T1 = 273; T2 = 330;
plt = ContourPlot[plotFunction[T, Z], {T, T1, T2}, {Z, 1, 50},
PlotRange -> All, ContourLabels -> {labelFunction, None},

What I did is to separately define the function to be plotted, so I can invoke it independently in the ContourPlot as usual, and also in the generation of the ContourLabels inside the plot. The latter makes it possible to re-calculate the correct function values when the contour label is drawn. The specification of the form ContourLabels -> {labelFunction, None} has as its first element the labelFunction that does this re-calculation and also wraps the output in a Text element. Here, None` stands for the (unwanted) tooltip function.