# 3D Quiver Plot and animation

**URL:** <https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645>\
**Category:** General Usage\
**Tags:** plotting, 3d, gnuplot, gaston\
**Created:** [August 9, 2020, 10:34pm UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645 "2020-08-09T22:34:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)\
**Post date:** [August 9, 2020, 10:34pm UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/1 "2020-08-09T22:34:29Z")

</div>

I’m trying to plot 3D Quiver plot with Julia Plots package, it appears that Plots still does not support 3D Quiver. so I’m trying to see if there are any other packages such as PyPlot that has the facility to plot 3D Quiver.

> using PyCall, PyPlot  
> using Plots, DataFrames
> 
> df = DataFrame()  
> df.x = [-5 ,-4.552786405 ,-4.105572809 ,-3.211145618 ,-1.422291236 ,0]  
> df.y = [10 ,9.105572809 ,8.211145618 ,6.422291236 ,2.844582472 ,0]  
> df.z = [125 ,103.6393202 ,84.27864045 ,51.5572809 ,10.1145618 ,0]  
> df.u = [0.447213595 ,0.447213595 ,0.894427191 ,1.788854382 ,1.422291236 ,0]  
> df.v = [-0.894427191 ,-0.894427191 ,-1.788854382 ,-3.577708764 ,-2.844582472 ,0]  
> df.w = [-21.36067977 ,-19.36067977 ,-32.72135955 ,-41.4427191 ,-10.1145618 ,0]

Here is the output with `GNUPLOT`:

 ![sample](https://global.discourse-cdn.com/julialang/original/3X/2/0/20380391064b2d2a1c951140b66bebbfd41caaf0.png)

I’m unable to reproduce this in `Julia`. When I tried using the following code using `PyPlot`. I got strange output. Is there any way to create 3D plot in `Julia` without using `PyPlot`?

> pygui(true)
> 
> fig = figure()  
> ax = fig.gca(projection=“3d”)  
> ax.quiver(df[!,1],df[!,2],df[!,3],df[!,4],df[!,5],df[!,6])

.

---

<div class="post-metadata">

**Author:** ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)\
**Post date:** [August 9, 2020, 10:36pm UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/2 "2020-08-09T22:36:01Z")

</div>

Since I’m unable to post two images because of I’m a new user. Reposting:

I also need to animate this data as shown below. Can you please let me know how can this be achieved in `Julia`?

 ![introduction](https://global.discourse-cdn.com/julialang/original/3X/6/1/61a2a0fdba4951fd2422af9f00158f62a1fbba08.gif)

Thanks

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 10, 2020, 1:01am UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/3 "2020-08-10T01:01:01Z")

</div>

Makie.jl is the best option for this kind of thing.

---

<div class="post-metadata">

**Author:** ![sriharitn](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sriharitn](https://discourse.julialang.org/u/sriharitn)\
**Post date:** [August 11, 2020, 12:06am UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/4 "2020-08-11T00:06:33Z")

</div>

Thanks, I had difficulty installing Make.jl in first place, exactly the same issue reported [here](https://github.com/JuliaPlots/Makie.jl/issues/599) after many hours of struggle I finally installed it.

Unfortunately, the 3D plots and also even regular surface plots did not scale well and did not have proper aspect ratio. Very low quality.

I ended using `Plots` and `marker =:rtriangle` that provided work around to create 3D quiver plot. It worked perfectly.

Thanks so much

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [August 17, 2020, 2:45am UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/5 "2020-08-17T02:45:39Z")

</div>

Using Gaston:

```julia
using Gaston

x = [-5 ,-4.552786405 ,-4.105572809 ,-3.211145618 ,-1.422291236 ,0]
y = [10 ,9.105572809 ,8.211145618 ,6.422291236 ,2.844582472 ,0]
z = [125 ,103.6393202 ,84.27864045 ,51.5572809 ,10.1145618 ,0]
dx = [0.447213595 ,0.447213595 ,0.894427191 ,1.788854382 ,1.422291236 ,0]
dy = [-0.894427191 ,-0.894427191 ,-1.788854382 ,-3.577708764 ,-2.844582472 ,0]
dz = [-21.36067977 ,-19.36067977 ,-32.72135955 ,-41.4427191 ,-10.1145618 ,0]

surf(x, y, z, supp = [dx dy dz], w = "vectors filled head", lw = 2,
            Axes(xlabel = :x, ylabel = :y, zlabel = :z, view = (55, 62)))

```

produces:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/f/ef23930c0f5bf1f7f53e39e263ccc791a0bfeff2.png)

The animation is easy to obtain with the techniques shown [here](https://mbaz.github.io/Gaston.jl/stable/3d-gallery/#Animation-1) – don’t hesitate to ask if you need help with it.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [September 4, 2020, 8:47am UTC](https://discourse.julialang.org/t/3d-quiver-plot-and-animation/44645/6 "2020-09-04T08:47:17Z")

</div>

Similar to @mbaz solution with Gnuplot the solution is similar…

```julia
using Gnuplot
x = [-5 ,-4.552786405 ,-4.105572809 ,-3.211145618 ,-1.422291236 ,0]
y = [10 ,9.105572809 ,8.211145618 ,6.422291236 ,2.844582472 ,0]
z = [125 ,103.6393202 ,84.27864045 ,51.5572809 ,10.1145618 ,0]
dx = [0.447213595 ,0.447213595 ,0.894427191 ,1.788854382 ,1.422291236 ,0]
dy = [-0.894427191 ,-0.894427191 ,-1.788854382 ,-3.577708764 ,-2.844582472 ,0]
dz = [-21.36067977 ,-19.36067977 ,-32.72135955 ,-41.4427191 ,-10.1145618 ,0]
@gsp xlab = "x" ylab = "y" zlab = "z" :-
@gsp :- x y z dx dy dz "w vectors filled head lw 1.2 lc 'black' not"

```

![quiver2](https://global.discourse-cdn.com/julialang/original/3X/e/2/e22d495ae6471901a472e14119fd29ce112ea3e3.png)  
this also works in 2D

```julia
@gp xlab = "x" ylab = "y" :-
@gp :- x y dx dy "w vectors filled head lw 1.2 lc 'black' not"

```

![quiver2d](https://global.discourse-cdn.com/julialang/original/3X/6/4/6431cb30d4c6c08b98913786c4f2882f3de105a6.png)
