Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access arrow positions/directions of streamplot object? #4666

Closed
chakravala opened this issue Dec 13, 2024 · 4 comments
Closed

How to access arrow positions/directions of streamplot object? #4666

chakravala opened this issue Dec 13, 2024 · 4 comments

Comments

@chakravala
Copy link

How can the arrow positions and directions be accessed of a streamplot plot object?

Specifically, I'd like to update the directions of the arrows and also need the positions of the arrows too.

@chakravala chakravala changed the title How to access the arrow positions/directions from streamplot plot object? How to access arrow positions/directions of streamplot object? Dec 13, 2024
@chakravala
Copy link
Author

without understanding how these plot objects work it seems difficult to access the streamplot arrow positions/directions, but somebody out there knows how to answer this with a quick solution.

@ffreyer
Copy link
Collaborator

ffreyer commented Dec 19, 2024

The positions and directions are rather internal to plot. If you want to modify them you'll have to fight quite a bit. The arrows are drawn by p = sp.plots[2] (with sp being the streamplot), which has the positions as p.args[1]. You can get and technically also update those. But they'll also be updated by the plot if any of the arguments get updated or gridsize, stepsize, maxsteps, density or color updates:

data = lift(p, p.f, p.limits, p.gridsize, p.stepsize, p.maxsteps, p.density, p.color) do f, limits, resolution, stepsize, maxsteps, density, color_func

You can get the rotation from p.rotation. In 3D they are Vec3fs that set the direction of the mesh, updated by the same inputs as positions. In 2D they are rotation angles which update on scene.camera.projectionview and scene.viewport on top of the above, i.e. also when you change the view in any way.
In the end, you could do something like this

sp = streamplot!(...)
onany(sp.f, sp.limits, sp.gridsize, sp.stepsize, sp.maxsteps, sp.density, sp.color, a.scene.camera.projectionview, a.scene.viewport) do _1, _2, _3, _4, _5, _6, _7, _8, _9
    pos = sp.plots[2].args[1][]
    rot = sp.plots[2].rotation[]
    ...
    sp.plots[2].args[1][] = new_pos
    sp.plots[2].rotation[] = new_rot
end

to overwrite whatever a (2D) streamplot does whenever it updates.

@chakravala
Copy link
Author

Excellent, thank you. Also, not sure what you mean by "changing the view in any way" as I did not need the "onany ... do" thingy when I move the 3D plot view with the mouse.

@ffreyer
Copy link
Collaborator

ffreyer commented Dec 19, 2024

Yea the view thing only applies if the plot limits are 2D (or equivalently if sp.plots[2] isa Scatter). Otherwise (sp.plots[2] isa MeshScatter) it won't reset rotations when you change the view. The other things in the onany (other than projectionview and viewport) should still matter though. I.e. changing sp.color should overwrite your overwrites without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants