我正在使用此處Player定義的影片類。它非常好,因為它包含一個播放按鈕控制臺,我用它來完成各種設定,例如影片熱圖。
但是,我在使用quiver.
我不會加載定義類本身的所有代碼,但這是我的示例,我嘗試在其中為一系列箭頭設定影片。時間 t 處的箭頭大小等于信號 2*sin(t) 的值:
fig,ax=plt.subplots(1)
t = np.linspace(0,6*np.pi, num=100)
s = 2*np.sin(t)
radius=s
x= np.multiply(radius,np.cos(t))
y =np.multiply( radius, np.sin(t))
point_vector,=ax.quiver(0,0,[],[])
def update(i):
point_vector.set_UVC(x[i],y[i])
ani = Player(fig, update, maxi=len(t)-1)
plt.show()
錯誤訊息指出
ValueError: Argument U has a size 0 which does not match 1, the number of arrow
positions
我相信這是由 quiver 命令本身引起的。
uj5u.com熱心網友回復:
以下應該可以解決問題。注意:
- 我繪制了箭袋給它最初的方向。錯誤訊息準確地告訴您:x、y 和 u、v 必須具有相同的大小。
ax.quiver只回傳一個句柄,因此等號前沒有逗號。- 我添加了一些關鍵字引數以更好地可視化箭袋。
- 我調整了軸限制以獲得更好的可視化。
fig,ax=plt.subplots(1)
t = np.linspace(0,6*np.pi, num=100)
s = 2*np.sin(t)
radius=s
x = np.multiply(radius,np.cos(t))
y = np.multiply( radius, np.sin(t))
point_vector=ax.quiver(0, 0, x[0], y[0], angles='xy', scale_units='xy', scale=1)
l = x.max()
if y.max() > l:
l = y.max()
ax.set_xlim(-l, l)
ax.set_ylim(-l, l)
ax.set_aspect("equal")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/529736.html
