【发布时间】: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,
【问题讨论】:
-
你可以在这里找到答案stackoverflow.com/questions/16249466/…
标签: python matplotlib tkinter raspberry-pi