使用Matplotlib在两个点之间使用一条线显示偏差



我的数据集中有4分(xy坐标(

coordinates =     [[1,2], [10,11], [3,4], [14,15]]

现在,使用matplotlib绘制它们很容易。但是我想将它们显示为第一点和第二点之间的偏差。看起来应该像这样

1,2 --- 10,11
3,4 --- 14,15

----是虚线。

fig2 = plt.figure()
shapeplot1 = fig2.add_subplot(111)
coordinates = [[1,2], [10,11], [3,4], [14,15]]
data = np.array(coordinates)
x1, y1 = data.T
shapeplot1.scatter(x1,y1, color='red')
plt.show()

好吧,我找到了答案。一个人可以特别给图函数给出两个点。

fig2 = plt.figure()
shapeplot1 = fig2.add_subplot(111)
coordinates = [[1,2], [10,11], [12,12], [14,15]]
data = np.array(coordinates)
x1, y1 = data.T
shapeplot1.scatter(x1,y1, color='red')
shapeplot1.plot([coordinates[0][0], coordinates[1][0]], [coordinates[0][1], coordinates[1][1]])
shapeplot1.plot([coordinates[2][0], coordinates[3][0]], [coordinates[2][1], coordinates[3][1]])
plt.show()

相关内容

最新更新