Hello I want generate a unit vector which points in a random direction in three-dimensional space, but I need help with quiver 3d because this code gives me ValueError: need at least one array to concatenate
. Thanks!
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
np.random.seed(420)
campione = 10 # I want generate 10 vectors to plot
phi = 2*np.pi * np.random.random(size=campione)
theta = np.arccos(1 - 2*np.random.random(size=campione))
vett3D = np.array([ np.sin(theta)*np.cos(phi), np.sin(theta)*np.sin(phi), np.cos(theta) ])
origine = np.zeros((3,campione))
fig = plt.figure(num=None, figsize=(8, 6), dpi=800, facecolor='w', edgecolor='k')
ax = fig.gca(projection='3d')
ax.quiver(origine, vett3D)
plt.show()
Aucun commentaire:
Enregistrer un commentaire