Unable to make 3d quiver plot

I have 3 dimensional data, but it looks like the only available package to do this is PyPlot, but this available example is not working with my environment (Julia 1.2.0), and returns an error saying Unkown projection '3d'. [quote=“jw3126, post:3, topic:2117”]
using PyPlot pygui(true) fig = figure() ax = fig:gca N = 10 x,y,z,u,v,w = [randn(N) for _ in 1:6] ax[:quiver](x,y,z, u,v,w)
[/quote]
Are there any current examples that would create this plot with the current Julia and package versions?

This isn’t so much a julia issue as a PyPlot issue. If you run the Python equivalent of the code in your post you get the same error message. For example, to get a 3D axes object in Python you can do

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

The equivalent code in julia (plus the bit to actually make the quiver plot) is the following:

using PyCall, PyPlot
mpl = pyimport("mpl_toolkits.mplot3d")
fig = figure()
ax = fig.add_subplot(111, projection="3d")
N = 10
x,y,z,u,v,w = [randn(N) for _ in 1:6]
ax.quiver(x,y,z, u,v,w)

Note the pyimport statement that loads the mpl_toolkits.mplot3d module. Also, the clunky ax[:quiver] syntax is no longer necessary. Thanks to some really cool work in PyCall.jl you can use the . syntax to access methods of Python objects from julia.

Edit: You mentioned PyPlot in your original post so I gave a PyPlot solution. I haven’t actually tried it but it seems that Makie and possibly other plotting platforms in julia can do this. Here’s a related Makie example: https://simondanisch.github.io/ReferenceImages/gallery/arrows_3d/index.html

1 Like