2017-04-20 44 views
0

超級簡單的問題,我知道,但這是我第一天使用python,必須學會快速使用它。 我想使用顫抖(它必須抖動)繪製3D矢量。 爲了簡單起見,如果我想繪製矢量(1,1,1)並在下面的圖片中看到它(當然是在正確的方向上),我該怎麼做? 這就是我一直在努力做的事情:在Python中使用顫抖來繪製一個3d矢量

import matplotlib.pyplot as plt 
plt.quiver(0, 0, 0, 1, 1, 1, scale=1, color='g') 

enter image description here

回答

0

plt.quiver僅適用於一維和二維數組。您應該使用mplot3d展現你的身材在3個維度:

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.set_xlim3d(0, 0.8) 
ax.set_ylim3d(0, 0.8) 
ax.set_zlim3d(0, 0.8) 
ax.quiver(0, 0, 0, 1, 1, 1, length = 0.5, normalize = True) 
plt.show() 

我建議你讀pyplot.quiveraxes3d.quiver的文檔。

+0

非常感謝! –