Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing an arrow with specified direction on a point in scatter plot in Julia

Is there a way to draw a scatter plot in Julia (preferably with gr backend), in which every point has an arrow pointing to a specified direction on it?

Specifically, my task is to create a gif image with multiple moving points with a small arrow on every point pointing to the direction of its velocity.

like image 227
Sato Avatar asked Jan 25 '23 18:01

Sato


1 Answers

So, you want to plot a vector field, right?

The "arrow plot" you are looking for, is usually called quiver-plot in many programming languages. In Julia, too.

If you use Plots.jl the syntax is quiver(x,y,quiver=(u,v)), where x and y are the coordinate vectors and u and v the arrow magnitude vectors.

If you use GR or PyPlot directly the syntax is possibly a bit different.

Small Example

using Plots
gr()
N = 10
x = rand(1:10,N)
y = rand(1:10,N)
u = rand(N)
v = rand(N)
scatter(x,y)
quiver!(x,y,quiver=(u,v))

quiver plot example

like image 112
max xilian Avatar answered Feb 02 '23 08:02

max xilian