2
$\begingroup$

I have contour plots, such as

plot = ContourPlot[Sqrt[(x - 2)^2 + (y - 2)^2 - 5], {x, -15, 15}, {y, -15, 15}, Contours -> {4}] /. _Polygon -> Sequence[]

I have successfully found the numerical area enclosed using Stokes' theorem, essentially the "x dy" case shown here.

points = Transpose[Cases[Normal@plot, Line[pts_] :> pts, Infinity][[1, 
   All]]];  
area = N[Abs[Rest[First[points]].Last[ListCorrelate[{1, -1}, #1] & /@ points]]] 

What I would like to accomplish now is to apply the found area as a Tooltip[] on the contour plot.

However, this isn't working properly:

Tooltip[ContourPlot[Sqrt[(x - 2)^2 + (y - 2)^2 - 5], {x, -15, 15}, {y, -15, 15}, Contours -> {4}] /. _Polygon -> Sequence[],"example"]

enter image description here

"example" comes up as a tooltip anywhere on the whole plot area, not just when the cursor is on the contour line. Also, sometimes it doesn't show "example"; it only shows like "ex" and then is cut off by white space.

How can I implement this properly?

$\endgroup$
1

1 Answer 1

1
$\begingroup$

You can proceed with ReplaceAll:

ContourPlot[Sqrt[(x - 2)^2 + (y - 2)^2 - 5], {x, -15, 15}, {y, -15, 15}, 
   Contours -> {4}
 ] /. _Polygon -> Sequence[] /. Tooltip[x_, y_] :> Tooltip[x, "example"]

enter image description here

In case of many contours you can take control this way:

ContourPlot[Sqrt[(x - 2)^2 + (y - 2)^2 - 5], {x, -15, 15}, {y, -15, 15}, 
            Contours -> {2, 4}
           ] /. _Polygon -> Sequence[] /. Tooltip[x_, 4] :> Tooltip[x, "example"]

so now only the chosen one is switched.

$\endgroup$
4
  • $\begingroup$ Thanks! This solution works I'm nearly certain, but I'm still having a display issue which I fear might be something else. Does anyone know why this tooltip is not showing fully? $\endgroup$
    – Steve
    Commented Jan 16, 2014 at 20:27
  • $\begingroup$ @Steve I sometimes face this but I don't know the reason. Try maybe Pane["exaple"]. $\endgroup$
    – Kuba
    Commented Jan 16, 2014 at 20:29
  • $\begingroup$ Strange. Pane didn't fix it for me, but it did add a little extra white space below. Also, I tried "exampleeeeeeeeeeeeeeeeee" and the white box to the right extends. But the yellow background and text don't change, still "ex" and then cut off. $\endgroup$
    – Steve
    Commented Jan 16, 2014 at 20:32
  • $\begingroup$ @Steve I think it is frequently faced issue. If you fail to find an answer with serach engine I encourage you to post the question. $\endgroup$
    – Kuba
    Commented Jan 16, 2014 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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