I have some problems related to the matplotlib glitter graph, which itself is built into the Tkinter GUI - the whole program will ultimately run on a raspberry Pi. The question includes different levels, this is my first question, so sorry in advance for any aversion.
In a few words I do the following: I am working on the Tk GUI to read several sensors at the same time, and I would like to have some updating of the sensor data in this GUI in real time, I would like to have each measured value on a separate frame, so I decided create a class for each sensor. One of the sensors is a flow sensor, which is read and displayed as follows:
import Tkinter as Tk
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from Backend import Backend
t0 = datetime.now()
def time_difference(t1, t2):
delta = t2-t1
delta = delta.total_seconds()
return delta
class FlowFig():
def __init__(self, master):
self.t = []
self.Flow = []
self.fig = plt.figure(figsize=(4,4))
self.ax = self.fig.add_subplot(111)
self.ax.set_title("Flow Control Monitor")
self.ax.set_xlabel("Time")
self.ax.set_ylabel("Flow")
self.ax.axis([0,100,0,5])
self.line = self.ax.plot(self.t, self.Flow, '-')
self.canvas = FigureCanvasTkAgg(self.fig, master = master)
self.canvas.show()
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
self.ax.grid(True)
self.Data= Backend()
self.Data.initialize()
def update(self):
self.t.append(time_difference(t0, datetime.now()))
Flow,_,_ = self.Data.get_adc_val(1)
self.Flow.append(Flow)
if len(self.t) > 200:
del self.t[0]
del self.Flow[0]
self.ax.set_xlim([np.min(self.t), np.max(self.t)])
self.line[0].set_data(self.t, self.Flow)
self.canvas.restore_region(self.background)
self.ax.draw_artist(self.line[0])
self.canvas.blit(self.ax.bbox)
root.after(25, Flowmonitor.Flowdata.update)
class FlowPage(Tk.Frame):
def __init__(self, parent, controller):
Tk.Frame.__init__(self,parent)
self.parent = parent
self.FlowPlot = FlowFig(self)
self.FlowPlot.canvas.get_tk_widget().grid(row=0, column=0, rowspan=9, columnspan=9)
root= Tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
Flowmonitor = FlowPage(root, root)
Flowmonitor.grid(row =0, column=0, rowspan =10, columnspan=10)
Flowmonitor.rowconfigure(0, weight=1)
Flowmonitor.columnconfigure(0, weight=1)
root.after(25, Flowmonitor.FlowPlot.update)
root.mainloop()
:
copy_from_bbox(self.ax.bbox), , , . , blush bbox (copy_from_bbox(self.fig.bbox)) this
fig.bbox ax.bbox,
, :
- , missmatch? , , , , . , , , bbox.expanded() copy_from_bbox()
.blit() vs. .draw() .
, , . fps = 10, 10 . - (, ) blit? ( , , β 1)
, alltogether: , - , ? ? ?
/, ^^
, , -, , .
!