5
$\begingroup$

Since this behavior is connected to How to add contour labels for contour lines?, I thought it worth pointing out this issue here on the site. It concerns the option ContourLabels to ContourPlot, when the form is

ContourLabels -> f

where f is a function of the form f[x, y, z] that constructs a label for the point {x, y} and label z.

In the first paradigm ContourPlot[f, {x, xmin, xmax}, {y, ymin], ymax]}] the labels are constructed as one would expect:

ContourPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},
  Contours -> {0.5}, ContourShading -> None, 
  ContourLabels -> (Text[0.5, {#1, #2}] & @@ Sow[{##}] &)] // Reap

enter image description here

In the second paradigm ContourPlot[f == g, {x, xmin, xmax}, {y, ymin], ymax]}] the labels are constructed but discarded:

ContourPlot[Sin[x] Sin[y] == 0.5, {x, -3, 3}, {y, -3, 3}, 
  ContourLabels -> (Text[0.5, {#1, #2}] & @@ Sow[{##}] &)] // Reap

enter image description here

If one compares the graphics, in the first case, there are two Inset[] expressions, one for each label. In the second, there are no Inset[] expressions.

The fact that the third z argument to the label constructor is different in the two cases is expected and seems irrelevant to the issue.

Another probably irrelevant observation is that the following does construct a Tooltip for each curve, although the labels are still discarded:

ContourLabels -> {Text[0.5, {#1, #2}] &, Tooltip[#1, #2] &}

Is there a way to get ContourLabels to work when the input is an equation or list of equations? Is it a bug?

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.