From 2a0a62d201927dae4e8db3fb1b107a081a70ffaf Mon Sep 17 00:00:00 2001 From: marques <20172333133@m.scnu.edu.cn> Date: Thu, 4 Sep 2025 11:45:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9F=A9=E5=BD=A2=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=89=88=E6=9C=AC=E7=9A=84matplotlib=E4=B8=ADaxvspan?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84=E5=AF=B9=E8=B1=A1=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_SA_label_v2.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/func/Module_SA_label_v2.py b/func/Module_SA_label_v2.py index b2e9010..59f13f1 100644 --- a/func/Module_SA_label_v2.py +++ b/func/Module_SA_label_v2.py @@ -12,7 +12,7 @@ from matplotlib import gridspec from matplotlib.backends.backend_qt import NavigationToolbar2QT from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg from matplotlib.collections import PolyCollection -from matplotlib.patches import Rectangle +from matplotlib.patches import Rectangle, Polygon from numpy import array, zeros, append, linspace, place, nan from overrides import overrides @@ -2004,15 +2004,16 @@ class MainWindow_SA_label(QMainWindow): def __get_x_and_width__(self, event_rect): """Get the width of a rectangle in data coordinates.""" - # pyside6.9.0 axvspan 返回的是一个Rectangle对象 - # pyside6.9.1 axvspan 返回的是一个PolyCollection对象 + # matplotlib >=3.9 axvspan 返回的是一个Rectangle对象 + # matplorlib < 3.9 axvspan 返回的是一个PolyCollection对象 if isinstance(event_rect, Rectangle): x = event_rect.get_x() width = event_rect.get_width() - elif isinstance(event_rect, PolyCollection): - verts = event_rect.get_paths()[0].vertices + elif isinstance(event_rect, Polygon): + verts = event_rect.get_xy() x = verts[0, 0] width = verts[2, 0] - verts[0, 0] + else: raise TypeError("Unsupported event_rect type") return x, width