[英]Quiver plot arrows using Matplotlib
我正在嘗試使用列表I4
制作一個箭袋 plot 。 在I4[0]
中, (0,0)
和(1,0)
分別代表起始 position 和箭頭方向。 但是,當前的 output 與預期的不匹配。 我在這里附上兩者。
import matplotlib.pyplot as plt
I4 = [[(0, 0), (1, 0)], [(0, 0), (0, -1)], [(1, 0), (1, -1)], [(0, -1), (1, -1)]]
fig, ax = plt.subplots(figsize = (10,10))
for i in range(0,len(I4)):
ax.quiver(I4[i][0], I4[i][1])
plt.show()
當前的 output 是
預期的 output 是
或者,您可以使用plt.arrow
( 此處為文檔):
import matplotlib.pyplot as plt
I4 = [(0, 0),(1, 1),(0, 1), (0, 1)]
dI4=[(1,0),(0,-1),(1,0),(0,-1)]
texts=['(0,-1)','(1,-1)','(1,0)','(0,0)']
textxy=[(0,0),(1,0),(1,1),(0,1)]
fig, ax = plt.subplots(figsize = (10,10))
for i in range(len(I4)):
ax.arrow(I4[i][0], I4[i][1],dI4[i][0],dI4[i][1],length_includes_head=True,head_width=0.05,color='k',lw=3)
if i<2:
dy=-0.1
else:
dy=0.1
plt.text(textxy[i][0], textxy[i][1]+dy,texts[i],fontsize=20)
ax.set_aspect('equal')
ax.set_xlim([-0.5,1.5])
ax.set_ylim([-0.5,1.5])
plt.axis('off')
plt.show()
output 給出:
請用help(ax.quiver)
查看文檔:您會看到需要指定ax.quiver(x, y, u, v)
其中 x, y 是起始坐標,u, v 代表方向。
在實踐中,您需要解壓縮列表,如下所示:
ax.quiver(*I4[i][0], *I4[i][1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.