I am trying to plot the lines that connect starting (x,y) and ending (x,y) That means a line will be connecting (x1start,y1start) to (x1end,y1end) I have multiple rows in data frame. The sample data frame that replicate the actual dataframe and shown below:
df = pd.DataFrame()
df ['Xstart'] = [1,2,3,4,5]
df ['Xend'] = [6,8,9,10,12]
df ['Ystart'] = [0,1,2,3,4]
df ['Yend'] = [6,8,9,10,12]
According to that, if we look at the first row of df, a line will be connecting (1,0) to (6,6) For that I am using for loop to draw a line for each row as follow:
fig,ax = plt.subplots()
fig.set_size_inches(7,5)
for i in range (len(df)):
ax.plot((df.iloc[i]['Xstart'],df.iloc[i]['Xend']),(df.iloc[i]['Ystart'],df.iloc[i]['Yend']))
ax.annotate("",xy = (df.iloc[i]['Xstart'],df.iloc[i]['Xend']),
xycoords = 'data',
xytext = (df.iloc[i]['Ystart'],df.iloc[i]['Yend']),
textcoords = 'data',
arrowprops = dict(arrowstyle = "->", connectionstyle = 'arc3', color = 'blue'))
plt.show()
I have the following error message when I run this.
I got the figure as shown below:
The arrow and line are in as expected. the arrow should be on the end point of each line.
Can anyone advise what is going on here?
Thanks,
Zep