0

I am receiving new data every one second from a sensor in rasperry pi and appending the same in existing list. I want to dynamically update Bar chart every second as per the list. I am able to do that but it is taking more than a second. Please suggest how to resolve this issue. In my program I am keeping blit= False. Please help how can I turn on the blit with bar chart, so that plot recovery may get faster.

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,
I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37
ashu
  • 1
  • 1
  • 1
    You can find the answer here https://stackoverflow.com/questions/16249466/dynamically-updating-a-bar-plot-in-matplotlib – I_Al-thamary Oct 24 '20 at 09:24

1 Answers1

0

The problem is that your FuncAnimation adds 250 ms to the time of receiving new data every one second. So, change it to be

 frames = 100
 self.ani= FuncAnimation(self.fig, self.animate, blit= True,frames=frames,
                              repeat=False,interval= 0)
I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37