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.

Mathematica graphics


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}]]?

  • 2
    $\begingroup$ The cut-off appears to be at Developer`$MaxMachineInteger $\endgroup$ – Simon Woods Apr 4 '15 at 20:35
  • 1
    $\begingroup$ Setting contours explicitly seems to fix it: Contours -> FindDivisions[{0, 2*10^19}, 10] $\endgroup$ – Simon Woods Apr 4 '15 at 21:10
  • $\begingroup$ @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. $\endgroup$ – bbgodfrey Apr 4 '15 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}, 
  PlotRangePadding -> 10]


This is a plot from version 8 (where a similar bug also appears, although it looks different from version 10). I checked that this works in version 10 as well.

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.

Of course, there is still the issue of the awfully chosen default label placement. To get around this, you could look at this answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.