优化绘图逻辑,增强X轴联动功能,调整刻度格式化

This commit is contained in:
2025-12-17 15:33:24 +08:00
parent 6845626fe9
commit 02fe64012c

View File

@ -9,7 +9,7 @@ from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication, QButtonGro
from matplotlib import gridspec, patches
from matplotlib.backends.backend_qt import NavigationToolbar2QT
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from matplotlib.ticker import FuncFormatter
from matplotlib.ticker import FuncFormatter, ScalarFormatter
from numpy import (diff, where, correlate, corrcoef, searchsorted, sum as np_sum, max as np_max, min as np_min, arange,
array,
append, delete, abs as np_abs, argmin as np_argmin, argmax as np_argmax, asarray)
@ -477,21 +477,35 @@ class MainWindow_precisely_align(QMainWindow):
else:
return f"{int(x - self.data.approximately_align_pos)}"
if sender == self.ui.pushButton_input:
self.gs = gridspec.GridSpec(2, 1, height_ratios=[1, 1])
self.fig.subplots_adjust(top=0.95, bottom=0.05, right=0.98, left=0.05, hspace=0.15, wspace=0)
self.ax0 = self.fig.add_subplot(self.gs[0])
self.ax0.grid(True)
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
self.ax1 = self.fig.add_subplot(self.gs[1], sharex=self.ax0, sharey=self.ax0)
# self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
self.ax1 = self.fig.add_subplot(self.gs[1], sharey=self.ax0)
self.ax1.grid(True)
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
# self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
Jpeak = self.data.Jpeak[:-2]
Rpeak = self.data.Rpeak[:-2]
self.ax0.set_title("JJIV")
self.ax1.set_title("RRIV")
def on_xlim_changed(ax):
if ax is self.ax0:
x0, x1 = ax.get_xlim()
self.ax1.callbacks.disconnect('xlim_changed')
self.ax1.set_xlim(x0, x1)
self.ax1.callbacks.connect('xlim_changed', on_xlim_changed)
elif ax is self.ax1:
x0, x1 = ax.get_xlim()
self.ax0.callbacks.disconnect('xlim_changed')
self.ax0.set_xlim(x0, x1)
self.ax0.callbacks.connect('xlim_changed', on_xlim_changed)
if self.data.BCG_early:
Jpeak = Jpeak - self.data.approximately_align_pos
@ -540,6 +554,12 @@ class MainWindow_precisely_align(QMainWindow):
self.ax1.stem(Rpeak, plot_element["RRIVs"],
markerfmt="C0.", linefmt=Constants.PLOT_COLOR_ORANGE,
label=Constants.PRECISELY_ALIGN_PLOT_LABEL_RRIV)
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
self.ax0.callbacks.connect('xlim_changed', on_xlim_changed)
self.ax1.callbacks.connect('xlim_changed', on_xlim_changed)
self.ax0.legend(loc=Constants.PLOT_UPPER_RIGHT)
self.ax1.legend(loc=Constants.PLOT_UPPER_RIGHT)
self.canvas.draw()