Plot 3d vector field

I would like to plot a 3d vector field (e.g. a couple of points with arrows attached), with some basic interactivity (rotatate, zoom, pan). What are my options to do this in julia? Are there some example codes with 3d vector fields? Is it possible with Plots.jl?

Matplotlib (and hence PyPlot) can do this.

1 Like

Thanks it works! Here is an example for those who may have the same question:

using PyPlot

pygui(true)

fig = figure()
ax = fig[:gca](projection="3d")

N = 10
x,y,z,u,v,w = [randn(N) for _ in 1:6]
ax[:quiver](x,y,z, u,v,w)

8 Likes

Hello.

I have a small problem with quiver in 3d. When setting the axes scale I am unable to set the z axis. x and y axes work well but somehow the 3d projection does not work with z.

Here is the same example as before

using PyPlot

pygui(true)

fig = figure()
ax = fig:gca

N = 10
x,y,z,u,v,w = [randn(N) for i in 1:6]
ax[:quiver](x,y,z, u,v,w)
axis([-5, 5, -5, 5])

This seems to work, however:

using PyPlot

pygui(true)

fig = figure()
ax = fig:gca

N = 10
x,y,z,u,v,w = [randn(N) for i in 1:6]
ax[:quiver](x,y,z, u,v,w)
axis([-5, 5, -5, 5, -5, 5])

This throws the following error:
ValueError(u’v must contain [xmin xmax ymin ymax]',) so only x and y axes are defined

Can anybody help?

Please quote code blocks with backticks (and without code errors).

using PyPlot

pygui(true)

fig = figure()
ax = fig[:gca](projection="3d")

N = 10
x,y,z,u,v,w = [randn(N) for _ in 1:6]
ax[:quiver](x,y,z, u,v,w)
xlim([0.0, 1.0])
ylim([0.0, 1.0])
zlim([0.0, 1.0])

works for me.

Thanks crstnbr
It works.
And sorry I will keep that in mind from now on.

Makie can also do this:
http://makie.juliaplots.org/stable/examples-arrows.html#Arrows-3D-1

4 Likes

Is Makie supported for 1.0.2? I’m getting errors trying to compile it with using.

just installed 1.0.2 and it seems to work fine on Makie#master AbstractPlotting#master… what version did you install?

[ Info: Precompiling Makie [ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a]
ERROR: LoadError: could not open file /home/oliver/.julia/packages/GLFW/pkSlg/deps/deps.jl
ERROR: LoadError: LoadError: Failed to precompile GLFW [f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98] to /home/oliver/.julia/compiled/v1.0/GLFW/n8HlT.ji.
ERROR: Failed to precompile Makie [ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a] to /home/oliver/.julia/compiled/v1.0/Makie/iZ1Bl.ji.