add serial readout. finish graph layout

This commit is contained in:
2025-04-22 22:14:43 +02:00
parent c81b2e3fbb
commit 58ebddcd48
7 changed files with 90 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
import asyncio
@@ -20,19 +20,9 @@ class FilterDevApp(tk.Tk):
self.title("JannTers Filter Evaluation Tool")
# Create a frame for the plot and sliders
self.frame = tk.Frame(self)
self.frame.pack(side=tk.LEFT, fill=tk.BOTH)
# Create a figure for plotting
self.fig, self.ax = plt.subplots()
self.ax2 = self.ax.twinx()
self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH)
# Create a frame for sliders
self.toolbar = tk.Frame(self, width=200, padx=10)
self.toolbar.pack(side=tk.RIGHT, fill=tk.Y)
self.toolbar.pack(side=tk.LEFT)
# Device Settings
self.record_form = RecordForm(self.toolbar, self.record_data)
@@ -46,6 +36,16 @@ class FilterDevApp(tk.Tk):
self.data_stats = DataStats(self.toolbar, self.reset)
# Create a figure for plotting
self.frame = tk.Frame(self)
self.frame.pack(side=tk.RIGHT)
self.fig, self.ax = plt.subplots()
self.ax2 = self.ax.twinx()
self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH)
NavigationToolbar2Tk(self.canvas, self.frame)
def update_plot(self):
if self.filter is None:
return
@@ -61,19 +61,27 @@ class FilterDevApp(tk.Tk):
# Generate data
x = df['timestamps']
y1 = df['weights']
# y1_g = df['calib_weights']
# y2 = df['filtered']
y2 = df['filtered']
y2_g = df['filtered_calib']
# Plot the data
self.ax.plot(x, y1)
# self.ax.plot(x, y2)
self.ax.plot(x, y1, label="raw")
self.ax.plot(x, y2, label="filtered")
# self.ax2.plot(x, y1_g)
self.ax2.plot(x, y2_g, label="filtered", color='green')
self.ax2.set_ylabel("Weight", color="green")
self.ax.set_xlabel("Time in ms")
self.ax.set_ylabel("Raw Weight")
self.ax.grid()
self.ax.legend(loc='upper left')
self.ax2.yaxis.set_label_position("right")
self.ax2.yaxis.tick_right()
self.ax2.legend(loc='lower right')
# self.ax2.plot(x, y1_g)
self.ax2.plot(x, y2_g, color="orange")
self.fig.tight_layout()
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH)
# Draw the updated plot
self.canvas.draw()