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()********

實現動態的關鍵就在********標記的四句

發佈了190 篇原創文章 · 獲贊 55 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章