4

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.

Sato
  • 1,013
  • 1
  • 12
  • 27

1 Answers1

8

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

max xilian
  • 463
  • 2
  • 11