From 5978d58dc54857514c9b7b92793a84ad01803fa3 Mon Sep 17 00:00:00 2001 From: awe Date: Wed, 4 Feb 2026 14:38:55 +0300 Subject: [PATCH] fix sub matplotlib --- .../visualization/matplotlib_backend.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/rfg_adc_plotter/visualization/matplotlib_backend.py b/rfg_adc_plotter/visualization/matplotlib_backend.py index 160e3e0..20d9c49 100644 --- a/rfg_adc_plotter/visualization/matplotlib_backend.py +++ b/rfg_adc_plotter/visualization/matplotlib_backend.py @@ -461,17 +461,24 @@ def run_matplotlib(args): # Обновление линии последнего свипа if current_sweep is not None: - if x_shared is not None and current_sweep.size <= x_shared.size: - xs = x_shared[: current_sweep.size] + # Применяем вычитание медианы для отображения + display_sweep = current_sweep + if median_subtract_enabled and median_data is not None: + take_median = min(current_sweep.size, median_data.size) + display_sweep = current_sweep.copy() + display_sweep[:take_median] = current_sweep[:take_median] - median_data[:take_median] + + if x_shared is not None and display_sweep.size <= x_shared.size: + xs = x_shared[: display_sweep.size] else: - xs = np.arange(current_sweep.size, dtype=np.int32) - line_obj.set_data(xs, current_sweep) + xs = np.arange(display_sweep.size, dtype=np.int32) + line_obj.set_data(xs, display_sweep) # Лимиты по X постоянные под текущую ширину - ax_line.set_xlim(0, max(1, current_sweep.size - 1)) + ax_line.set_xlim(0, max(1, display_sweep.size - 1)) # Адаптивные Y-лимиты (если не задан --ylim) if fixed_ylim is None: - y0 = float(np.nanmin(current_sweep)) - y1 = float(np.nanmax(current_sweep)) + y0 = float(np.nanmin(display_sweep)) + y1 = float(np.nanmax(display_sweep)) if np.isfinite(y0) and np.isfinite(y1): if y0 == y1: pad = max(1.0, abs(y0) * 0.05) @@ -484,7 +491,7 @@ def run_matplotlib(args): ax_line.set_ylim(y0, y1) # Обновление спектра и фазы текущего свипа - take_fft = min(int(current_sweep.size), FFT_LEN) + take_fft = min(int(display_sweep.size), FFT_LEN) if take_fft > 0 and freq_shared is not None: # Создаем буфер для полного FFT (с отрицательными частотами) fft_in = np.zeros((FFT_LEN,), dtype=np.float32) @@ -500,7 +507,7 @@ def run_matplotlib(args): data_points = min(data_points, take_fft, FFT_LEN - start_idx) # Подготовка данных с окном Хэннинга - seg = np.nan_to_num(current_sweep[:data_points], nan=0.0).astype(np.float32, copy=False) + seg = np.nan_to_num(display_sweep[:data_points], nan=0.0).astype(np.float32, copy=False) win = np.hanning(data_points).astype(np.float32) # Размещаем данные в правильной позиции