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