Skip to content

Commit a6c50bb

Browse files
committed
Fix issues we encountered in matplotlib 3.10
This will also unpin the matplotlib version as a result. I did not immediately see any further issues, but if we encounter more in the future, we can hopefully fix them quickly. Thanks @patquem for the pointer in #1772! Signed-off-by: Patrick Avery <[email protected]>
1 parent 29e4b31 commit a6c50bb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

hexrdgui/image_canvas.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from PySide6.QtCore import QThreadPool, QTimer, Signal, Qt
77
from PySide6.QtWidgets import QFileDialog, QMessageBox, QProgressDialog
88

9+
from matplotlib.artist import Artist
910
from matplotlib.axes import Axes
1011
from matplotlib.backends.backend_qtagg import FigureCanvas
1112
from matplotlib.figure import Figure
@@ -187,10 +188,10 @@ def clear(self):
187188
self.clear_figure()
188189

189190
def clear_figure(self):
191+
self.remove_all_overlay_artists()
190192
self.figure.clear()
191193
self.raw_axes.clear()
192194
self.axes_images.clear()
193-
self.remove_all_overlay_artists()
194195
self.clear_azimuthal_integral_axis()
195196
self.mode = None
196197

@@ -768,7 +769,7 @@ def update_overlays(self):
768769

769770
def clear_detector_borders(self):
770771
while self.cached_detector_borders:
771-
self.cached_detector_borders.pop(0).remove()
772+
_safe_remove_artist(self.cached_detector_borders.pop(0))
772773

773774
self.draw_idle()
774775

@@ -792,7 +793,7 @@ def draw_detector_borders(self):
792793

793794
def clear_stereo_border_artists(self):
794795
while self.stereo_border_artists:
795-
self.stereo_border_artists.pop(0).remove()
796+
_safe_remove_artist(self.stereo_border_artists.pop(0))
796797

797798
self.draw_idle()
798799

@@ -2222,3 +2223,14 @@ def to_stereo(xys, panel, iviewer):
22222223
raise Exception(f'Unknown mode: {mode}')
22232224

22242225
return funcs[mode]
2226+
2227+
2228+
def _safe_remove_artist(artist: Artist):
2229+
# Starting in matplotlib 3.10, we cannot remove artists from a figure
2230+
# that has already been cleared. I don't know of any easy way to check
2231+
# if the axis has been cleared, though, so for now, we just try to
2232+
# remove the artist and ignore the relevant exception if it occurs.
2233+
try:
2234+
artist.remove()
2235+
except NotImplementedError:
2236+
pass

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
install_reqs = [
77
'hexrd',
88
'fabio>=0.11',
9-
# We have some issue removing artists in matplotlib 3.10
10-
# Fix the matplotlib version until that is resolved.
11-
'matplotlib<3.10',
9+
'matplotlib',
1210
'Pillow',
1311
# PySide 6.8.0 is causing segmentation faults in the testing
1412
# Keep this version downgraded until that is fixed.

0 commit comments

Comments
 (0)