标识散点:plt.scatter(x, y)

可选项s修改散点大小,color修改颜色

1
plt.scatter(thisNodeLoc[0], thisNodeLoc[1], s=10, color='b')

连线:plt.plot([x1, y1], [x2, y2])

1
plt.plot([thisNodeLoc[0], sendToNodeLoc[0]], [thisNodeLoc[1], sendToNodeLoc[1]])

注释文字:plt.annotate(txt, xy=(), xytext=())

xy处填注释点坐标,xytext处填文本位置,可加偏移offset

1
plt.annotate(thisNodeLoc, xy=(thisNodeLoc[0], thisNodeLoc[1]), xytext=(thisNodeLoc[0]+1, thisNodeLoc[1]+1))

限制坐标区间:

1
2
plt.xlim(-2200,2200)
plt.ylim(-2200,2200)
1
2
3
4
5
6
7
8
9
10
for n in range(0, nodeNum):
thisNodeLoc = [nodes[n].locX, nodes[n].locY]
sendToNodeLoc = [nodes[n].sendTo.locX, nodes[n].sendTo.locY]
plt.scatter(thisNodeLoc[0], thisNodeLoc[1], s=10, color='b')
plt.plot([thisNodeLoc[0], sendToNodeLoc[0]], [thisNodeLoc[1], sendToNodeLoc[1]])
plt.annotate(thisNodeLoc, xy=(thisNodeLoc[0], thisNodeLoc[1]), xytext=(thisNodeLoc[0]+1, thisNodeLoc[1]+1))

plt.xlim(-2200,2200)
plt.ylim(-2200,2200)
plt.show()

最后记得用plt.show()将其显示出来