Old
I would like to make the locator follow a plot, giving the coordinates as it moves. I don't really know where to start with this one, but I would like the dynamic plot to look something like this:
the code for which is as follows:
Plot[{Sqrt[x]}, {x, 0, 10}, PlotRange -> {{0, 12}, {0, 3.5}},
Epilog -> {PointSize[Large], Red, Point[{4, 2}]}]
with the locator showing its coordinates as it is moved along the plot. Obviously, the movement of the locator needs to be constrained to the plot, just as it is constrained to the coordinates of the circle in this Wolfram Documentation example:
by the following code:
Deploy[DynamicModule[{p = {1, 0}}, Graphics[{Red, Disk[],
Locator[Dynamic[p, (p = Normalize[#]) &]]}, PlotRange -> 1.5]]]
basically, so it behaves in a similar way to Google graphs:
where the coordinates appear to the top right of the plot.
New
@Timothy Wofford The solution you gave works great for functions like Sqrt[x], but runs into difficulties when complex values are encountered. For example:
generated by the code:
f[x_] := ((\[Pi]^x/Zeta[x])^(1/x)/\[Pi]) - 1/Zeta[x]
Manipulate[Plot[f[x], {x, 0, 10}, Epilog -> {PointSize[Large], Red,
Tooltip[Point[#], #] &@{p[[1]], f[p[[1]]]}}, PlotLabel ->
{p[[1]], f[p[[1]]]}], {{p, {1, 0}}, Locator, Appearance -> None},
AppearanceElements -> None]
shows as a red screen when the locator moves off screen into the imaginary values, generating an error screen as follows:
Is there any way of preventing this from happening? - ie, from stopping the locator moving past {1,0}?
p = {0, 0}
is an example point forSqrt
(and really any {x,y} would work with x>0 as the y coordinate of the locator is not used). For your new function,p={x,y}
where y is any value and x is in the domain of your new function. $\endgroup$