Message Boards Message Boards

Tracing curve in a Graphic (Position Data?)

Posted 11 years ago

To established exactly what I mean, if you've ever pulled a graph on Wolfram|Alpha, you would notice on mouse over of the graph the cross hairs that pop up and a point that traces the graph and displays position data of the point. I have yet to figure out how to replicate that function, the point following a graph and displaying position data (I don't care about the cross hair cosmetics).

Maybe i'm just bad at using the documentation center, and i'm still new with Mathmatica. Web searches did turn up a Mathmatica function called PlotTrace but apparently it was an old function or I don't know what because that returns nothing in Mathmatica 9. Anyone have any ideas? I apologize if this has been asked before, my search turned up no posts related.

P.S. I'm not talking about locator graphics that you can drag where you want it, the idea is it traces the function graph (returning the location of its position X,Y coordinates).

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

Group Abstract Group Abstract