Unable to make 3d quiver plot

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