@@ -473,30 +473,35 @@ def confoundplot(tseries, gs_ts, gs_dist=None, name=None,
473473 ax_ts .spines ["left" ].set_visible (False )
474474 # ax_ts.yaxis.set_ticks_position('left')
475475
476- # Calculate Y limits
477- def_ylims = [tseries [~ np .isnan (tseries )].min () - 0.1 * abs (tseries [~ np .isnan (tseries )].min ()),
478- 1.1 * tseries [~ np .isnan (tseries )].max ()]
479- if ylims is not None :
480- if ylims [0 ] is not None :
481- def_ylims [0 ] = min ([def_ylims [0 ], ylims [0 ]])
482- if ylims [1 ] is not None :
483- def_ylims [1 ] = max ([def_ylims [1 ], ylims [1 ]])
484-
485- # Add space for plot title and mean/SD annotation
486- def_ylims [0 ] -= 0.1 * (def_ylims [1 ] - def_ylims [0 ])
487-
488- ax_ts .set_ylim (def_ylims )
489- # yticks = sorted(def_ylims)
476+
490477 ax_ts .set_yticks ([])
491478 ax_ts .set_yticklabels ([])
492- # ax_ts.set_yticks(yticks)
493- # ax_ts.set_yticklabels(['%.02f' % y for y in yticks])
494-
495- # Annotate stats
496- maxv = tseries [~ np .isnan (tseries )].max ()
497- mean = tseries [~ np .isnan (tseries )].mean ()
498- stdv = tseries [~ np .isnan (tseries )].std ()
499- p95 = np .percentile (tseries [~ np .isnan (tseries )], 95.0 )
479+
480+ nonnan = tseries [~ np .isnan (tseries )]
481+ if nonnan .size > 0 :
482+ # Calculate Y limits
483+ def_ylims = [nonnan .min () - 0.1 * abs (nonnan .min ()), 1.1 * nonnan .max ()]
484+ if ylims is not None :
485+ if ylims [0 ] is not None :
486+ def_ylims [0 ] = min ([def_ylims [0 ], ylims [0 ]])
487+ if ylims [1 ] is not None :
488+ def_ylims [1 ] = max ([def_ylims [1 ], ylims [1 ]])
489+
490+ # Add space for plot title and mean/SD annotation
491+ def_ylims [0 ] -= 0.1 * (def_ylims [1 ] - def_ylims [0 ])
492+
493+ ax_ts .set_ylim (def_ylims )
494+
495+ # Annotate stats
496+ maxv = nonnan .max ()
497+ mean = nonnan .mean ()
498+ stdv = nonnan .std ()
499+ p95 = np .percentile (nonnan , 95.0 )
500+ else :
501+ maxv = 0
502+ mean = 0
503+ stdv = 0
504+ p95 = 0
500505
501506 stats_label = (r'max: {max:.3f}{units} $\bullet$ mean: {mean:.3f}{units} '
502507 r'$\bullet$ $\sigma$: {sigma:.3f}' ).format (
0 commit comments