5
$\begingroup$

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

At least two previous questions, 109778 and 13545, have identified bugs in contour labelling. Here are two more. I would welcome workarounds that do not require a completely customized approach.

In the course of generating the plot in my answer to question 258180, I noticed that the ToolTip incorrectly identified contour values. Adding the option, ContourLabels -> All, (to make the issue more visible) produced the same result for contour labels. Specifically,

ctr = {1/2, 0, -(1/2), -((Sqrt[Pi] Gamma[4/3])/(2 Gamma[5/6])), -0.902182, -1.40218, -1.90218};
ComplexContourPlot[Im[Hypergeometric2F1[1/3, 1/2, 4/3, I z^3] z], 
    {z, -4 - 6 I, 4 + 2 I}, Contours -> N@ctr, ContourShading -> None, ContourLabels -> All, 
    ContourStyle -> {Red, Orange, Brown, Green, Blue, Cyan, Magenta}]

enter image description here

The seven curves are correctly labeled. In order from the top, they are {0.5, 0, -0.5, -0.701091, -0.902182, -1.40218, -1.90218}. However, when N is not applied to ctr,

ComplexContourPlot[Im[Hypergeometric2F1[1/3, 1/2, 4/3, I z^3] z], 
    {z, -4 - 6 I, 4 + 2 I}, Contours -> ctr, ContourShading -> None, ContourLabels -> All, 
    ContourStyle -> {Red, Orange, Brown, Green, Blue, Cyan, Magenta}]

enter image description here

the labels are incorrect. In order from the top, they are {1/2, 0, -(1/2), -((Sqrt[Pi] Gamma[4/3])/(2 Gamma[5/6])), -0.902182, -1.40218, -1.90218}.

A second, perhaps related, issue is based on question 109778. Replace 0.7 by 0.707 in the code for the first plot of the question, and the resulting plot is labeled as one would expect. However, if 0.7 is replaced by Sqrt[2]/2, that label is omitted from the plot, and some other contours are mislabeled.

dat = Table[Re[Sqrt[1 - x^2 - y^2]], {x, -1.1, 1.1, 0.01}, {y, -1.1, 1.1, 0.01}];
ListContourPlot[dat, Contours -> {1., 0.9, 0.8, Sqrt[2]/2, 0.6, 0.5}, ContourLabels -> All]

enter image description here

So, are these bugs and what are convenient workarounds?

$\endgroup$
2
  • 4
    $\begingroup$ There is a standard bugs header that is supposed to have a fixed syntax to facilitate an automatic bugs tracker. I don't know if anyone still uses the tracker, and it's rather difficult to get users to stick to the syntax. I don't much care anymore, because it's like swimming upstream. But since you went to the trouble of approximating the header, I thought I might point out that it doesn't conform to the specified syntax, in case it matters to you. Cheers, $\endgroup$
    – Michael E2
    Dec 5 '21 at 1:39
  • $\begingroup$ @MichaelE2 - I have made the correction. Thanks. $\endgroup$
    – bbgodfrey
    Dec 5 '21 at 5:28
3
$\begingroup$

A work-around: Use Contours -> N @ ctr to set the contour levels and use two custom functions to replace the numerical contour and tooltip labels with ctr in setting ContourLabels:

ClearAll[contourLabelsF, contourTooltipsF]

contourLabelsF[clist_] := Text[AssociationThread[N@clist, clist] @ N @ #3, {#, #2}] &;

contourTooltipsF[clist_] := Tooltip[#, AssociationThread[N @ clist, clist] @ N @ #2] &;

Examples:

ComplexContourPlot[Im[Hypergeometric2F1[1/3, 1/2, 4/3, I z^3] z], 
 {z, -4 - 6 I, 4 + 2 I}, 
 Contours -> N @ctr, 
 ContourShading -> None, 
 ContourLabels -> {contourLabelsF[ctr], contourTooltipsF[ctr]}, 
 ContourStyle -> {Red, Orange, Brown, Green, Blue, Cyan, Magenta}, 
 ImageSize -> 600] 

enter image description here

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

ctrs = {1., 0.9, 0.8, Sqrt[2]/2, 0.6, 0.5};

ListContourPlot[dat, 
 Contours -> N @ ctrs, 
 ContourLabels -> {contourLabelsF[ctrs], contourTooltipsF[ctrs]}, 
 ImageSize -> 600]

enter image description here

$\endgroup$
2
$\begingroup$

An alternative work-around: Use Contours -> N @ ctr and ContourLabels -> All to set the contour levels and labels, and post-process the output to replace numerical contour and tooltip labels with ctr:

ClearAll[postProcess]
postProcess[clist_] := Module[{asso = AssociationThread[N@clist, clist]}, 
   ReplaceAll[{Tooltip[a_, b_] :> Tooltip[a, asso @ b], 
     Text[a_, b___] :> Text[asso @ N @ a, b]}]];

Examples:

postProcess[ctr] @
  ComplexContourPlot[Im[Hypergeometric2F1[1/3, 1/2, 4/3, I z^3] z], 
    {z, -4 - 6 I, 4 + 2 I}, 
    Contours -> N @ctr, 
    ContourShading -> None, 
    ContourLabels -> All, 
    ContourStyle -> {Red, Orange, Brown, Green, Blue, Cyan, Magenta}, 
    ImageSize -> 600]

enter image description here

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

ctrs = {1., 0.9, 0.8, Sqrt[2]/2, 0.6, 0.5};
    
postProcess[ctrs] @
  ListContourPlot[dat, Contours -> N[ctrs], ContourLabels -> All, ImageSize -> 600] 

enter image description here

$\endgroup$

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.