【问题标题】:Dynamic updating Bar plot in python using matpltlib every second每秒使用matpltlib在python中动态更新条形图
【发布时间】:2020-10-24 17:34:32
【问题描述】:

我每秒钟从 rasperry pi 中的传感器接收新数据,并将其附加到现有列表中。我想根据列表每秒动态更新条形图。我能够做到这一点,但这需要一秒钟以上的时间。请建议如何解决此问题。在我的程序中,我保持 blit= False。请帮助我如何打开带有条形图的 blit,以便绘图恢复可能更快。

class PlotAnimate(): #threading.Thread
    def __init__(self):
        x_vals=[0,0,0,0,0,0,0,0,0]
        y_vals=[0,0,0,0,0,0,0,0,0]
        data= [x_vals, y_vals]
        ls_param=[0,19]
        index= count()
        self.fig= plt.figure(num =1,facecolor = "black")
        self.ax= self.fig.add_subplot(111)
        self.ax.set_facecolor("black")
        plt.axis('off')
        plt.tick_params(axis = "both", left = False, right = False, bottom = False, top =False)
        self.bar1 = FigureCanvasTkAgg(self.fig,root.t1.frame_chart)
        self.ani= FuncAnimation(self.fig, self.animate, blit= False,interval= 250)
        plt.tight_layout()
        self.bar1.get_tk_widget().pack(side=LEFT, fill=BOTH, expand = 1)

    def animate(self,i):
            #chart update
            index = []
            for j in range(root.t1.hist_size):#
                index.append(j)
            plt.tight_layout()
            self.ax.cla()
            plt.axis('off')
            plt.tick_params(axis = "both", left = False, right = False, bottom = False, top =False)
            self.ax.bar(index,root.t1.dose_list,color = root.t1.colors)#self.bar_dose,

【问题讨论】:

标签: python matplotlib tkinter raspberry-pi


【解决方案1】:

问题是您的FuncAnimation250 ms 添加到每秒接收新数据的时间。所以,把它改成

 frames = 100
 self.ani= FuncAnimation(self.fig, self.animate, blit= True,frames=frames,
                              repeat=False,interval= 0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    相关资源
    最近更新 更多