Skip to content

Commit b8ce984

Browse files
committed
Added option to create the figure from previously defined matplotlib.pyplot.ax() object and percentile for W-test confidence interval
1 parent 26e6d3a commit b8ce984

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

csep/utils/plots.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,30 +1243,38 @@ def _get_marker_t_color(distribution):
12431243

12441244
return fmt
12451245

1246-
def _get_marker_w_color(distribution):
1246+
def _get_marker_w_color(distribution, percentile):
12471247
"""Returns matplotlib marker style as fmt string"""
12481248

1249-
if distribution < 0.05:
1249+
if distribution < (1 - percentile/100):
12501250
fmt = True
12511251
else:
12521252
fmt = False
12531253

12541254
return fmt
12551255

1256-
def plot_comparison_test(results_t, results_w=None, plot_args=None):
1256+
def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None):
12571257
"""Plots list of T-Test (and W-Test) Results"""
12581258

12591259
if plot_args is None:
12601260
plot_args = {}
1261+
1262+
figsize = plot_args.get('figsize', None)
12611263
title = plot_args.get('title', 'CSEP1 Comparison Test')
12621264
xlabel = plot_args.get('xlabel', 'X')
12631265
ylabel = plot_args.get('ylabel', 'Y')
12641266
ylims = plot_args.get('ylims', (None, None))
12651267
capsize = plot_args.get('capsize', 2)
12661268
linewidth = plot_args.get('linewidth', 1)
12671269
markersize = plot_args.get('markersize', 2)
1270+
percentile = plot_args.get('percentile', 95)
1271+
1272+
if axes is None:
1273+
fig, ax = pyplot.subplots(figsize=figsize)
1274+
else:
1275+
ax = axes
1276+
fig = ax.get_figure()
12681277

1269-
fig, ax = pyplot.subplots()
12701278
ax.axhline(y=0, linestyle='--', color='black')
12711279

12721280
Results = zip(results_t, results_w) if results_w else zip(results_t)
@@ -1284,7 +1292,7 @@ def plot_comparison_test(results_t, results_w=None, plot_args=None):
12841292
linewidth=linewidth, capsize=capsize)
12851293

12861294
if result_w is not None:
1287-
if _get_marker_w_color(result_w.quantile):
1295+
if _get_marker_w_color(result_w.quantile, percentile):
12881296
facecolor = _get_marker_t_color(result_t.test_distribution)
12891297
else:
12901298
facecolor = 'white'

0 commit comments

Comments
 (0)