From 03054638575700ef2623fb76c53396372eac5ba4 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 13 Jun 2025 18:21:17 +0200 Subject: [PATCH] MainCode/adalm1000_logger.py aktualisiert 1. Verbesserte auto_scale_axes() Methode: (D) --- MainCode/adalm1000_logger.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index 7eb67ad..cfd7e92 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -835,33 +835,36 @@ class BatteryTester: self._last_plot_time = time.time() def auto_scale_axes(self): - """Auto-scale plot axes with appropriate padding""" + """Auto-scale plot axes with appropriate padding and strict boundaries""" if not self.time_data: return - # X-axis scaling + # X-axis scaling with 5% padding but don't exceed current max time min_time = 0 - max_time = self.time_data[-1] * 1.05 # 5% padding + max_time = self.time_data[-1] current_xlim = self.ax.get_xlim() - if abs(current_xlim[1] - max_time) > (max_time * 0.1): # 10% change threshold - self.ax.set_xlim(min_time, max_time) - self.ax2.set_xlim(min_time, max_time) - # Voltage axis scaling + # Only expand axis if new data exceeds current view + if max_time > current_xlim[1] * 0.95: # 95% threshold to start expanding + new_max = max_time * 1.05 # 5% padding + self.ax.set_xlim(min_time, new_max) + self.ax2.set_xlim(min_time, new_max) + + # Voltage axis scaling with strict boundaries voltage_padding = 0.2 if self.voltage_data: min_voltage = max(0, min(self.voltage_data) - voltage_padding) - max_voltage = max(self.voltage_data) + voltage_padding + max_voltage = min(5.0, max(self.voltage_data) + voltage_padding) # 5V hardware limit current_ylim = self.ax.get_ylim() if (abs(current_ylim[0] - min_voltage) > 0.1 or abs(current_ylim[1] - max_voltage) > 0.1): self.ax.set_ylim(min_voltage, max_voltage) - # Current axis scaling + # Current axis scaling with strict boundaries current_padding = 0.05 if self.current_data: - min_current = min(self.current_data) - current_padding - max_current = max(self.current_data) + current_padding + min_current = max(-0.25, min(self.current_data) - current_padding) # -250mA limit + max_current = min(0.25, max(self.current_data) + current_padding) # +250mA limit current_ylim2 = self.ax2.get_ylim() if (abs(current_ylim2[0] - min_current) > 0.02 or abs(current_ylim2[1] - max_current) > 0.02):