Skip to content

Commit aa2a94e

Browse files
authored
Merge pull request #1833 from HEXRD/fix-matplotlib-3.10
Fix issues we encountered in matplotlib 3.10
2 parents 3993f83 + 6d43b6a commit aa2a94e

18 files changed

+72
-47
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/blit_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from matplotlib.artist import Artist
44

5+
from hexrdgui.utils.matplotlib import remove_artist
6+
57

68
class BlitManager:
79
def __init__(self, canvas):
@@ -63,7 +65,7 @@ def remove_artists(self, *path):
6365
d = d[key]
6466

6567
for artist in _recursive_yield_artists(d):
66-
artist.remove()
68+
remove_artist(artist)
6769

6870
if parent:
6971
del parent[key]

hexrdgui/calibration/calibration_dialog_callbacks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from hexrdgui.hexrd_config import HexrdConfig
1919
from hexrdgui.utils import instr_to_internal_dict
2020
from hexrdgui.utils.abc_qobject import ABCQObject
21+
from hexrdgui.utils.matplotlib import remove_artist
2122

2223

2324
# Number of decimal places to round calibration parameters
@@ -312,7 +313,7 @@ def on_undo_run_clicked(self):
312313

313314
def clear_drawn_picks(self):
314315
while self.draw_picks_lines:
315-
self.draw_picks_lines.pop(0).remove()
316+
remove_artist(self.draw_picks_lines.pop(0))
316317

317318
self.canvas.draw_idle()
318319

hexrdgui/calibration/hedm/calibration_results_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from hexrdgui.navigation_toolbar import NavigationToolbar
99
from hexrdgui.ui_loader import UiLoader
10+
from hexrdgui.utils.matplotlib import remove_artist
1011

1112

1213
DEFAULT_STYLE = 'rx'
@@ -134,7 +135,7 @@ def grain_ids_to_plot(self):
134135

135136
def clear_artists(self):
136137
while self.artists:
137-
self.artists.pop(0).remove()
138+
remove_artist(self.artists.pop(0))
138139

139140
def update_canvas(self):
140141
self.clear_artists()

hexrdgui/hand_picked_fibers_widget.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from hexrdgui.fiber_pick_utils import _angles_from_orientation, _pick_to_fiber
1010
from hexrdgui.ui_loader import UiLoader
1111
from hexrdgui.utils import block_signals
12+
from hexrdgui.utils.matplotlib import remove_artist
1213

1314

1415
class HandPickedFibersWidget(QObject):
@@ -177,7 +178,7 @@ def general_spots(self, fibers):
177178

178179
def clear_current_plot(self):
179180
if hasattr(self, '_current_lines'):
180-
self._current_lines.remove()
181+
remove_artist(self._current_lines)
181182
del self._current_lines
182183

183184
def update_current_plot(self):
@@ -269,7 +270,7 @@ def picked(self, v):
269270
def clear_selected_artists(self):
270271
lines = getattr(self, '_selected_artists', [])
271272
while lines:
272-
lines.pop(0).remove()
273+
remove_artist(lines.pop(0))
273274

274275
@property
275276
def selected_rows(self):

hexrdgui/image_canvas.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
q_to_tth,
4444
tth_to_q,
4545
)
46+
from hexrdgui.utils.matplotlib import remove_artist
4647
from hexrdgui.utils.tth_distortion import apply_tth_distortion_if_needed
4748
from hexrdgui.waterfall_plot import WaterfallPlotDialog
4849

@@ -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

@@ -248,24 +249,24 @@ def clear_azimuthal_integral_axis(self):
248249

249250
def clear_wppf_plot(self):
250251
if self.wppf_plot:
251-
self.wppf_plot.remove()
252+
remove_artist(self.wppf_plot)
252253
self.wppf_plot = None
253254

254255
if self.wppf_background_plot:
255-
self.wppf_background_plot.remove()
256+
remove_artist(self.wppf_background_plot)
256257
self.wppf_background_plot = None
257258

258259
if self.wppf_amorphous_plot:
259-
self.wppf_amorphous_plot.remove()
260+
remove_artist(self.wppf_amorphous_plot)
260261
self.wppf_amorphous_plot = None
261262

262263
if self.wppf_difference_plot:
263-
self.wppf_difference_plot.remove()
264+
remove_artist(self.wppf_difference_plot)
264265
self.wppf_difference_plot = None
265266

266267
def clear_auto_picked_data_artists(self):
267268
while self.auto_picked_data_artists:
268-
self.auto_picked_data_artists.pop(0).remove()
269+
remove_artist(self.auto_picked_data_artists.pop(0))
269270

270271
def load_images(self, image_names):
271272
HexrdConfig().emit_update_status_bar('Loading image view...')
@@ -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+
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+
remove_artist(self.stereo_border_artists.pop(0))
879880

880881
self.draw_idle()
881882

@@ -916,7 +917,7 @@ def draw_auto_picked_data(self):
916917

917918
def clear_saturation(self):
918919
for t in self.saturation_texts:
919-
t.remove()
920+
remove_artist(t)
920921
self.saturation_texts.clear()
921922
self.draw_idle()
922923

@@ -981,7 +982,7 @@ def compute_saturation_and_size(detector_name):
981982

982983
def clear_beam_marker(self):
983984
while self.beam_marker_artists:
984-
self.beam_marker_artists.pop(0).remove()
985+
remove_artist(self.beam_marker_artists.pop(0))
985986

986987
def update_beam_marker(self):
987988
self.clear_beam_marker()
@@ -1766,7 +1767,7 @@ def clear_azimuthal_overlay_artists(self):
17661767
while self.azimuthal_overlay_artists:
17671768
item = self.azimuthal_overlay_artists.pop(0)
17681769
for artist in item['artists'].values():
1769-
artist.remove()
1770+
remove_artist(artist)
17701771

17711772
def save_azimuthal_plot(self):
17721773
if self.mode != ViewType.polar:
@@ -1835,7 +1836,7 @@ def update_azimuthal_plot_overlays(self):
18351836
self.azimuthal_integral_axis.legend()
18361837
elif (axis := self.azimuthal_integral_axis) and axis.get_legend():
18371838
# Only remove the legend if the axis exists and it has a legend
1838-
axis.get_legend().remove()
1839+
remove_artist(axis.get_legend())
18391840
self.draw_idle()
18401841

18411842
def update_azimuthal_integral_plot(self):
@@ -2268,7 +2269,7 @@ def update_mask_boundaries(self, axis):
22682269

22692270
def clear_mask_boundaries(self):
22702271
for artist in self._mask_boundary_artists:
2271-
artist.remove()
2272+
remove_artist(artist)
22722273

22732274
self._mask_boundary_artists.clear()
22742275

hexrdgui/indexing/fit_grains_results_dialog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from hexrdgui.ui_loader import UiLoader
2727
from hexrdgui.utils import block_signals
2828
from hexrdgui.utils.dialog import add_help_url
29+
from hexrdgui.utils.matplotlib import remove_artist
2930

3031

3132
COORDS_SLICE = slice(6, 9)
@@ -219,15 +220,15 @@ def update_enable_states(self):
219220
def clear_artists(self):
220221
# Colorbar must be removed before the scatter artist
221222
if self.colorbar is not None:
222-
self.colorbar.remove()
223+
remove_artist(self.colorbar)
223224
self.colorbar = None
224225

225226
if self.scatter_artist is not None:
226-
self.scatter_artist.remove()
227+
remove_artist(self.scatter_artist)
227228
self.scatter_artist = None
228229

229230
if self.highlight_artist is not None:
230-
self.highlight_artist.remove()
231+
remove_artist(self.highlight_artist)
231232
self.highlight_artist = None
232233

233234
def on_colorby_changed(self):
@@ -444,7 +445,7 @@ def highlight_selected_grains(self):
444445
selected_grain_ids = self.ui.table_view.selected_grain_ids
445446

446447
if self.highlight_artist is not None:
447-
self.highlight_artist.remove()
448+
remove_artist(self.highlight_artist)
448449

449450
# Now draw the highlight markers for these selected grains
450451
data = self.converted_data[:, COORDS_SLICE][selected_grain_ids].T

hexrdgui/indexing/indexing_results_dialog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from hexrdgui.ui_loader import UiLoader
2121
from hexrdgui.utils import block_signals
2222
from hexrdgui.utils.dialog import add_help_url
23+
from hexrdgui.utils.matplotlib import remove_artist
2324

2425

2526
class IndexingResultsDialog(QObject):
@@ -113,7 +114,7 @@ def export_grains(self, filename):
113114
if filename.suffix.lower() == '.npz':
114115
# Save as an npz
115116
grain_data = GrainData.from_array(grains)
116-
grain_data.save(selected_file)
117+
grain_data.save(filename)
117118
else:
118119
# Save as txt
119120
write_grains_txt(grains, filename)
@@ -299,7 +300,7 @@ def update_plot(self):
299300

300301
def clear_spot_lines(self):
301302
if hasattr(self, '_spot_lines'):
302-
self._spot_lines.remove()
303+
remove_artist(self._spot_lines)
303304
del self._spot_lines
304305

305306
def update_spots(self):

hexrdgui/indexing/ome_maps_viewer_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from hexrdgui.ui_loader import UiLoader
2929
from hexrdgui.utils import block_signals
3030
from hexrdgui.utils.dialog import add_help_url
31+
from hexrdgui.utils.matplotlib import remove_artist
3132

3233
import hexrdgui.constants
3334
import hexrdgui.resources.indexing
@@ -540,7 +541,7 @@ def display_spots(self):
540541

541542
def clear_spot_lines(self):
542543
if hasattr(self, '_spot_lines'):
543-
self._spot_lines.remove()
544+
remove_artist(self._spot_lines)
544545
del self._spot_lines
545546

546547
def update_spots(self):

hexrdgui/interactive_template.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from hexrdgui.hexrd_config import HexrdConfig
1111
from hexrdgui.utils import has_nan
12+
from hexrdgui.utils.matplotlib import remove_artist
1213
from hexrdgui.utils.polygon import polygon_to_mask
1314

1415

@@ -160,7 +161,7 @@ def rotation(self):
160161

161162
def clear(self):
162163
if self.shape in self.axis.patches:
163-
self.shape.remove()
164+
remove_artist(self.shape)
164165
self.redraw()
165166
self.total_rotation = 0.
166167

@@ -186,7 +187,7 @@ def toggle_boundaries(self, show):
186187
self.axis.add_patch(shape)
187188
if self.shape:
188189
self.shape = self.axis.patches[-1]
189-
self.shape.remove()
190+
remove_artist(self.shape)
190191
self.shape.set_linestyle(self.shape_styles[-1]['line'])
191192
self.axis.add_patch(self.shape)
192193
self.connect_translate_rotate()

0 commit comments

Comments
 (0)