# VectorPlot: How can I evaluate the vector field by clicking on the plot?

This seems like a basic feature that is somehow missing. Ideally we'd get something like a tooltip which shows the x,y position where I click (or of where the mouse is currently hovering) and the evaluated vector (or scalar in the case of a scalar field) at that position. I think this would be a great way to "get a feel for" the values because by default the arrows are scaled automatically so they fit so I don't know anything about the relative magnitude of a particular arrow.

I have found that this is a good way to get a tooltip which displays the current mouse coordinates really well, but it obviously won't evaluate my vector field for me.

• For the case of scalar field plot it's quite easy to see what's going on by just doing a 3D plot with it. Jul 5 '12 at 4:30
• Something like VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}] /. ar : Arrow[{p1_, p2_}] :> Tooltip[Arrow[{p1, p2}], p1]? Jul 5 '12 at 4:37
• @J.M. That's pretty good Jul 8 '12 at 20:35

There are many ways to do this. For example, using LocatorPane. Imagine this is your vector function:

f[x_, y_] := {-1 - x^2 + y, 1 + x - y^2}


Now this will do the trick, where first line is the coordinate, and second is the function f evaluated at the coordinate. Red dot will follow the mouse. You can also bring the numbers with PlotLabel outside the graphics not to block the view.

DynamicModule[{pt = {1, 0}},LocatorPane[Dynamic[pt],
VectorPlot[f[x, y], {x, -3, 3}, {y, -3, 3}, StreamPoints -> Coarse,
StreamColorFunction -> Hue, Epilog -> Dynamic@Inset[{pt, f @@ pt}, pt],
PerformanceGoal -> "Quality"], AutoAction -> True,
Appearance -> Style["\[FilledCircle]", Red]]] • Since the plot itself is static you can also do VectorPlot[..., Epilog -> Dynamic[...]] instead of Dynamic[VectorPlot[....]]. On my system this makes the plot a lot more responsive. Jul 5 '12 at 9:04
• @Heike Excellent point. The rule of thumb with Dynamic is to try bring it to the lowest level to avoid recomputing redundant things. I made the changes. Jul 5 '12 at 9:24
• This is beautiful. Jul 8 '12 at 20:36