轨迹图

1 输入一个二维list,输出轨迹图.

import matplotlib.pyplot as plt
# 定义函数,实现,输入二维list,画出点的轨迹的功能
def track_pic(spot):
    # 两种方法
    l = len(spot)
    fig, axs = plt.subplots()
    # fig=plt.figure()
    # axs=fig.add_subplot(111)
    for i in range(l-1):
        # 每次取两个
        a = spot[i:i+2]
        x1, y1 = a[0]
        x2, y2 = a[1]
        # 这个用于控制从起始点到终止点的连接方式
        # connectionstyle = "angle3,angleA=90,angleB=0"
        axs.plot([x1,x2], [y1,y2], ".")
        axs.annotate("", # 注释为空
                    xy=(x2, y2), xycoords='data',
                    xytext=(x1, y1), textcoords='data',
                    arrowprops=dict(
                                    arrowstyle="->", color="0.5",
                                    shrinkA=5, shrinkB=5,
                                    patchA=None, patchB=None,
                                    # connectionstyle=connectionstyle,
                                    ),
                    )
    plt.show()
spot = [[20,20],[3,4],[5,60],[7,86],[9,100]]
track_pic(spot=spot)
View Code

ttt

参考: https://matplotlib.org/gallery/userdemo/connectionstyle_demo.html#sphx-glr-gallery-userdemo-connectionstyle-demo-py

        

posted on 2020-01-07 19:36  吃我一枪  阅读(352)  评论(0编辑  收藏  举报

导航