我使用python绘制数据。如何为plot
中的每个点提供ID,然后从A=(1,2)
到B=(2,3)
绘制线
Lat=[1,2,3,4]
Long=[2,3,1,3]
id_point=[A,B,C,D]
plt.plot( Lat,Long , 'o', markerfacecolor=col, markeredgecolor='k', markersize=4)
答案 0 :(得分:1)
您可以通过以下方式执行此操作
def plotLine(p1, p2):
plt.plot( [p1[0], p2[0]], [p1[1], p2[1]] )
Lat = [1,2,3,4]
Long = [2,3,1,3]
id_point=['A','B','C','D']
# Fill a dictionary with the points
points = {} # Create empty dictionary
for idx, point in enumerate(zip(Lat,Long)):
points[id_point[idx]] = point
# Plot points and their names
plt.plot(Lat, Long,'o') #Plot the points as you did
for key in points:
plt.annotate(key, xy=points[key]) #Print name of point
plotLine(points['A'], points['B']) #Connect point A and B
plt.show()
points是一个包含以下内容的字典:
{'A': (1, 2), 'C': (3, 1), 'D': (4, 3), 'B': (2, 3)}
键是点的名称,每个值都是带坐标的元组。