python matpoltlib 动态画图

def line_many():
    plt.ion()********

    for i in range(100):
        plt.clf()*********
        name_list = ['0',"1","2","3","4","5","6"]
        num_list = [round(random.random()*100,2),round(random.random()*100,2),round(random.random()*100,2),round(random.random()*100,2),round(random.random()*100,2),round(random.random()*100,2),round(random.random()*100,2)]
        rects = plt.bar(range(len(num_list)), num_list, color='rgby')
        # X轴标题
        index = [0, 1, 2, 3,4,5,6]
        index = [float(c) for c in index]

        plt.ylim(ymax=110, ymin=0)
        plt.xticks(index, name_list)
        plt.ylabel("arrucay(%)")  # X轴标签
        for rect in rects:
            height = rect.get_height()
            plt.text(rect.get_x() + rect.get_width() / 2, height, str(height) + '%', ha='center', va='bottom')

        plt.pause(0.5) *******
        plt.ioff()********

实现动态的关键就在********标记的四句

发布了172 篇原创文章 · 获赞 52 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_32759777/article/details/103460278
今日推荐