一、python开发——用python实现时序图

python实现时序图

有些时候,我们需要使用python进行实现一些脚本分析工具。比如时序图分析,就是能够通过图示的方法清晰的反映函数调用的时序,进而可以精准知道程序的执行流程。
以下提供了一个展现时序图的python实现代码,可供各位参考使用:

import matplotlib.pyplot as plt
def plot_sequence_diagram(lines_list, lines_names, title, x_lable, y_lable, save_path):
    if len(lines_list) == 0 or len(lines_list) != len(lines_names):
        return
    for n in range(len(lines_list)):
        line_list = lines_list[n]
        x_list = []
        y_list = []
        for m in range(len(line_list)):
            x_list.append(line_list[m])
            y_list.append([n+10,n+10])
        for i in range(len(x_list)):
            plt.scatter(x_list[i], y_list[i], color='black', s=5)
            plt.plot(x_list[i], y_list[i])
            plt.annotate(s='%s'%(lines_names[n]),xy=(x_list[i][0],y_list[i][0]),xytext=(x_list[i][0],y_list[i][0]-5),\
                 weight='bold',color='aqua',arrowprops=dict(arrowstyle='-|>',connectionstyle='arc3',color='red'),\
                 bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k',lw=1 ,alpha=0.4))

        plt.grid(True)
        plt.xlim(0,100)
        plt.ylim(0,16)
        plt.title(title)
        plt.xlabel(x_lable)
        plt.ylabel(y_lable)

    plt.savefig("%s%s.jpg"%(save_path, title))
    plt.close()
if __name__ == '__main__':
    p1 = [[10, 20], [50, 60]]
    p2 = [[21, 31], [61, 71]]
    p3 = [[32, 42], [82, 92]]
    lines_list = [p1,p2,p3]
    plot_sequence_diagram(lines_list, ['p1','p2','p3'], "title", "x_lable", "y_lable", 'C:/Users/xt/Desktop/test/')

执行的效果图如下:
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

厚国兄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值