3
$\begingroup$

I was thinking if there is a way to obtain the values of a function from a streamline plot. This is what I mean:

Consider a typical streamline plot from the documentation: StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, StreamPoints -> {{{{1, 0}, Red}, {{-1, -1}, Green}, Automatic}}] with a typical output StreamPlot with specified stream points

My Question: is there a way one could dynamically display the value of the functions that were plotted for the green streamline for instance, as you hover your cursor along the line (green streamline)? Thank you.

$\endgroup$
4
  • 2
    $\begingroup$ You mean, display each point that went into drawing a particular stream line? $\endgroup$
    – J. M.'s torpor
    Oct 8 '16 at 4:47
  • $\begingroup$ I understand you mean something analoguous to: right click on the graph and select "get coordinates". $\endgroup$ Oct 8 '16 at 12:51
  • $\begingroup$ Thanks for your comment @Dr.WolfgangHintze. What I meant is what bbgodfrey actually showed. To display the corresponding value of the functions at a given coordinate. $\endgroup$
    – D. Andrew
    Oct 8 '16 at 14:44
  • 1
    $\begingroup$ In V12.2, due to a change in StreamPlot, one has to add the option StreamColorFunction -> None to reproduce the figure in the question. $\endgroup$
    – Michael E2
    Jan 11 at 2:36
4
$\begingroup$

Since ToolTip does not appear to work here, try

Dynamic[{loc = MousePosition["Graphics", {0, 0}], 
    {-1 - x^2 + y, 1 + x - y^2} /. {x -> First@loc, y -> Last@loc}}]

which gives a result that looks like

{{x, y}, {xstream, ystream}}

where x and y are the positions on the plot (the coordinates provided by Get Coordinate Tool as suggested by Dr. Wolfgang Hintze in a comment above), and xstream and ystream are the corresponding values of the functions there. For instance, when the mouse is at the tip of the Red streamline, the coordinates and values are approximately

((0.0308851, 1.0987}, {0.00331156, 0.101788}}

The output can be dressed up a bit, if desired, by

Dynamic[StringForm["loc = ``, val = ``", 
    loc = MousePosition["Graphics", {0, 0}], 
    val = {-1 - x^2 + y, 1 + x - y^2} /. {x -> First@loc, y -> Last@loc}]]
$\endgroup$
2
  • $\begingroup$ Thanks, @bbgodfrey. This is what I actually meant.This concept could be useful to gain some insight beforehand of what the solutions of some complex functions should be even before attempting to solve them. $\endgroup$
    – D. Andrew
    Oct 8 '16 at 14:52
  • $\begingroup$ @bbgodfrey excellent solution (+1). $\endgroup$ Oct 9 '16 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.