Issue
I am trying to make a quiver plot using the list I4
. In I4[0]
, (0,0)
and (1,0)
represent the starting position and the direction of the arrow respectively. However, the current output doesn't match the expected one. I attach both here.
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()
The current output is
The expected output is
Solution
Alternatively, you could use plt.arrow
(doc here):
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()
And the output gives:
Answered By - jylls
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.