@@ -257,63 +257,73 @@ def plot_items(
257
257
258
258
# Create figure
259
259
fig , axes = create_figure (n_subplots , sharex , sharey , figsize )
260
+ try :
261
+ if signal is not None :
262
+ plot_signal (
263
+ signal ,
264
+ sig_len ,
265
+ n_sig ,
266
+ fs ,
267
+ time_units ,
268
+ sig_style ,
269
+ axes ,
270
+ sampling_freq = sampling_freq ,
271
+ )
260
272
261
- if signal is not None :
262
- plot_signal (
263
- signal ,
264
- sig_len ,
265
- n_sig ,
266
- fs ,
267
- time_units ,
268
- sig_style ,
269
- axes ,
270
- sampling_freq = sampling_freq ,
271
- )
272
-
273
- if ann_samp is not None :
274
- plot_annotation (
275
- ann_samp ,
276
- n_annot ,
277
- ann_sym ,
278
- signal ,
279
- n_sig ,
280
- fs ,
281
- time_units ,
282
- ann_style ,
283
- axes ,
284
- sampling_freq = sampling_freq ,
285
- ann_freq = ann_freq ,
286
- )
287
-
288
- if ecg_grids :
289
- plot_ecg_grids (
290
- ecg_grids ,
291
- fs ,
292
- sig_units ,
293
- time_units ,
294
- axes ,
295
- sampling_freq = sampling_freq ,
296
- )
297
-
298
- # Add title and axis labels.
299
- # First, make sure that xlabel and ylabel inputs are valid
300
- if xlabel :
301
- if len (xlabel ) != signal .shape [1 ]:
302
- raise Exception (
303
- "The length of the xlabel must be the same as the "
304
- "signal: {} values" .format (signal .shape [1 ])
273
+ if ann_samp is not None :
274
+ plot_annotation (
275
+ ann_samp ,
276
+ n_annot ,
277
+ ann_sym ,
278
+ signal ,
279
+ n_sig ,
280
+ fs ,
281
+ time_units ,
282
+ ann_style ,
283
+ axes ,
284
+ sampling_freq = sampling_freq ,
285
+ ann_freq = ann_freq ,
305
286
)
306
287
307
- if ylabel :
308
- if len (ylabel ) != n_subplots :
309
- raise Exception (
310
- "The length of the ylabel must be the same as the "
311
- "signal: {} values" .format (n_subplots )
288
+ if ecg_grids :
289
+ plot_ecg_grids (
290
+ ecg_grids ,
291
+ fs ,
292
+ sig_units ,
293
+ time_units ,
294
+ axes ,
295
+ sampling_freq = sampling_freq ,
312
296
)
313
297
314
- label_figure (
315
- axes , n_subplots , time_units , sig_name , sig_units , xlabel , ylabel , title
316
- )
298
+ # Add title and axis labels.
299
+ # First, make sure that xlabel and ylabel inputs are valid
300
+ if xlabel :
301
+ if len (xlabel ) != signal .shape [1 ]:
302
+ raise Exception (
303
+ "The length of the xlabel must be the same as the "
304
+ "signal: {} values" .format (signal .shape [1 ])
305
+ )
306
+
307
+ if ylabel :
308
+ if len (ylabel ) != n_subplots :
309
+ raise Exception (
310
+ "The length of the ylabel must be the same as the "
311
+ "signal: {} values" .format (n_subplots )
312
+ )
313
+
314
+ label_figure (
315
+ axes ,
316
+ n_subplots ,
317
+ time_units ,
318
+ sig_name ,
319
+ sig_units ,
320
+ xlabel ,
321
+ ylabel ,
322
+ title ,
323
+ )
324
+ except BaseException :
325
+ plt .close (fig )
326
+ raise
317
327
318
328
if return_fig :
319
329
return fig
0 commit comments