You are reading an old version of the documentation (v1.4.2). For the latest version see https://matplotlib.org/stable/
matplotlib

Previous topic

mplot3d example code: polys3d_demo.py

Next topic

mplot3d example code: rotate_axes3d_demo.py

This Page

mplot3d example code: quiver3d_demo.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/quiver3d_demo.png
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')

x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
                      np.arange(-0.8, 1, 0.2),
                      np.arange(-0.8, 1, 0.8))

u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
     np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1)

plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)