Skip to content

Commit d24473d

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 3993f83 commit d24473d

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

conda.recipe/meta.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ requirements:
2323
- python
2424
- fabio
2525
- hexrd=={{ hexrd_version }}
26-
# We have some issue removing artists in matplotlib 3.10
27-
# Fix the matplotlib version until that is resolved.
28-
- matplotlib-base<3.10
26+
- matplotlib-base
2927
- Pillow
3028
- pyhdf
3129
# This next one is needed to fix the app name on Mac

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
@@ -232,10 +233,10 @@ def clear(self):
232233
self.clear_figure()
233234

234235
def clear_figure(self):
236+
self.remove_all_overlay_artists()
235237
self.figure.clear()
236238
self.raw_axes.clear()
237239
self.axes_images.clear()
238-
self.remove_all_overlay_artists()
239240
self.clear_azimuthal_integral_axis()
240241
self.mode = None
241242

@@ -851,7 +852,7 @@ def update_overlays(self):
851852

852853
def clear_detector_borders(self):
853854
while self.cached_detector_borders:
854-
self.cached_detector_borders.pop(0).remove()
855+
_safe_remove_artist(self.cached_detector_borders.pop(0))
855856

856857
self.draw_idle()
857858

@@ -875,7 +876,7 @@ def draw_detector_borders(self):
875876

876877
def clear_stereo_border_artists(self):
877878
while self.stereo_border_artists:
878-
self.stereo_border_artists.pop(0).remove()
879+
_safe_remove_artist(self.stereo_border_artists.pop(0))
879880

880881
self.draw_idle()
881882

@@ -2549,3 +2550,14 @@ def to_stereo(xys, panel, iviewer):
25492550
raise Exception(f'Unknown mode: {mode}')
25502551

25512552
return funcs[mode]
2553+
2554+
2555+
def _safe_remove_artist(artist: Artist):
2556+
# Starting in matplotlib 3.10, we cannot remove artists from a figure
2557+
# that has already been cleared. I don't know of any easy way to check
2558+
# if the axis has been cleared, though, so for now, we just try to
2559+
# remove the artist and ignore the relevant exception if it occurs.
2560+
try:
2561+
artist.remove()
2562+
except NotImplementedError:
2563+
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)