当鼠标光标移至Wolfram | Alpha中的2D图上时,会出现一条灰线,帮助您读取x和y轴上的坐标.
For example,我将鼠标悬停在以下Airy函数图的转折点之一上。
以上内容也可以在Mathematica内部使用
WolframAlpha["Plot Ai(x)", {{"Plot", 1}, "Content"}]
这具有显示定位坐标.的某种定位器的附加优势
如何在正常的Mathematica图形/图中模拟这种行为?
最佳答案
这是使用Nearest
的另一种方法,与Simon的方法有些不同:
plot = Plot[{Sin[x], Cos[x]}, {x, -2 Pi, 2 Pi}];
With[{nf = Nearest[Flatten[Cases[Normal[plot], Line[p_, ___] :> p, Infinity], 1]]},
Show[plot,
Epilog ->
Dynamic[DynamicModule[{
pt = First[nf[MousePosition[{"Graphics", Graphics}, {0, 0}]]],
scaled = Clip[MousePosition[{"GraphicsScaled", Graphics}, {0, 0}], {0, 1}]
},
{
{If[scaled === None, {},
{Lighter@Gray, Line[{
{Scaled[{scaled[[1]], 1}], Scaled[{scaled[[1]], 0}]},
{Scaled[{1, scaled[[2]]}], Scaled[{0, scaled[[2]]}]}
}]
}]},
{AbsolutePointSize[7], Point[pt], White, AbsolutePointSize[5], Point[pt]},
Text[Style[NumberForm[Row[pt, ", "], {5, 2}], 12, Background -> White], Offset[{7, 0}, pt], {-1, 0}]}
]]
]
]
这是根据我周围的例子综合而成的。 (我不喜欢自由浮动的垂线与点跟踪相结合;就其本身而言感觉还不错。)