Group Abstract Group Abstract

Message Boards Message Boards

Tracing curve in a Graphic (Position Data?)

Posted 12 years ago
POSTED BY: Zach Wolfe
4 Replies

If not use tooltip, I propose to plot with Text.

data = Table[{x, Cos[x]}, {x, -Pi, Pi, Pi/8}]
Graphics[Text[#[[2]], #] & /@ data]

plot with text

POSTED BY: Yu(u)ki IWABUCHI

Here is a crude preliminary version of what Szabolics hinted at:

CursorPlot[f_] := Module[{plot, max,},
   plot = Plot[f[x], {x, -2 Pi, 2 Pi}];

   (*calculate max bounds*)
   max = 1.1 Max@Abs@Flatten@
        (PlotRange /. AbsoluteOptions[plot]);

   Show[
    Plot[f[x], {x, -2 Pi, 2 Pi}],

    Graphics[Dynamic[Module[
       {x = (MousePosition["Graphics"] /. None -> {0, 0})[[1]]},

       {Gray,
        Line[{{x, -max}, {x, max}}],
        Line[{{-max, f[x]}, {max, f[x]}}],
        Black,
        Text["O", {x, f[x]}],
        Text[StringJoin[ToString /@ {
            "\n\n\t\t\t(", x, ", ", f[x], ")"}], {x, f[x]}]}

       ]]]]];

CursorPlot[Sin[#] &]

There's better ways to do a lot of what's here but this will at least give you a few ideas. Mainly it is the usage of Show in combination with Dynamic and MousePosition["Graphics"]. As always, it's a good idea to F1 any symbol/function you're unfamiliar with.

This functionality is not available by default in Mathematica, but it is easy to implement a practical version of it. With a little more work you could implement the same thing W|A has, but since that version is mainly better in presentation only, I won't bother with it.

First, you can use W|A directly form Mathematica. Try

== plot sin(x)

But I think this is not what you're looking for.

Try right clicking any graphics object, and choosing Get Coordinates in Mathematica. It'll show the coordinates of the point you hover. You can click several points to mark them, and copy their coordinates using Ctrl-C.

It is possible to customize this functionality using the CoordinatesToolOptions option.

f[x_] := Sin[x]

disp[{x_, y_}] := {x, f[x]}

Plot[f[x], {x, 0, 10}, 
 CoordinatesToolOptions -> {"DisplayFunction" -> disp, "CopiedValueFunction" -> disp}]

This version will display the function value in place of the $y$ coordinate.

POSTED BY: Szabolcs Horvát

I am not sure if this is answering you, But if you want to trace values on curve, ToolTip will work

data = Table[Tooltip[N@{x, Cos[x]}], {x, -Pi, Pi, .05}];
ListPlot[data, Joined -> True, Mesh -> Full]

Note: have to use Mesh->Full for the tooltip to show.

enter image description here

POSTED BY: Nasser M. Abbasi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard