9951 explained code solutions for 126 technologies


python-matplotlibHow to draw 3D vector


import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(0, 0, 0, 1, 2, 1)
ax.set_xlim([-1, 4])
ax.set_ylim([-1, 4])
ax.set_zlim([-1, 4])
plt.show()ctrl + c
import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

mpl_toolkits.mplot3d

toolkit to plot 3d charts

.add_subplot

create sub chart

projection='3d'

this will be 3d chart

.quiver(

plots arrow with given start point and arrow direction

.show()

render chart in a separate window


How to draw 3D vector, python matplotlib

Usage example

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(0, 0, 0, 1, 2, 1)
ax.set_xlim([-1, 4])
ax.set_ylim([-1, 4])
ax.set_zlim([-1, 4])
plt.show()