@@ -72,23 +72,41 @@ def load_plot_data(
72
72
current_contrast = data [current_idx ]
73
73
if len (index_group )> 0 :
74
74
for index in index_group :
75
- if index == 2 :
76
- current_plot_data = getattr (getattr (current_contrast , effect_attr ), contrast_attr )
77
- bootstraps .append (current_plot_data .bootstraps_delta_delta )
78
- differences .append (current_plot_data .difference )
79
- bcalows .append (current_plot_data .bca_low )
80
- bcahighs .append (current_plot_data .bca_high )
81
- elif index == 0 or index == 1 :
82
- current_plot_data = getattr (current_contrast , effect_attr )
83
- bootstraps .append (current_plot_data .results .bootstraps [index ])
84
- differences .append (current_plot_data .results .difference [index ])
85
- bcalows .append (current_plot_data .results .bca_low [index ])
86
- bcahighs .append (current_plot_data .results .bca_high [index ])
75
+ if contrast_type == 'delta2' :
76
+ if index == 2 :
77
+ current_plot_data = getattr (getattr (current_contrast , effect_attr ), contrast_attr )
78
+ bootstraps .append (current_plot_data .bootstraps_delta_delta )
79
+ differences .append (current_plot_data .difference )
80
+ bcalows .append (current_plot_data .bca_low )
81
+ bcahighs .append (current_plot_data .bca_high )
82
+ elif index == 0 or index == 1 :
83
+ current_plot_data = getattr (current_contrast , effect_attr )
84
+ bootstraps .append (current_plot_data .results .bootstraps [index ])
85
+ differences .append (current_plot_data .results .difference [index ])
86
+ bcalows .append (current_plot_data .results .bca_low [index ])
87
+ bcahighs .append (current_plot_data .results .bca_high [index ])
88
+ else :
89
+ raise ValueError ("The selected indices must be 0, 1, or 2." )
87
90
else :
88
- raise ValueError ("The selected indices must be 0, 1, or 2." )
91
+ num_of_groups = len (getattr (current_contrast , effect_attr ).results )
92
+ if index == num_of_groups :
93
+ current_plot_data = getattr (getattr (current_contrast , effect_attr ), contrast_attr )
94
+ bootstraps .append (current_plot_data .bootstraps_weighted_delta )
95
+ differences .append (current_plot_data .difference )
96
+ bcalows .append (current_plot_data .results .bca_low )
97
+ bcahighs .append (current_plot_data .results .bca_high )
98
+ elif index < num_of_groups :
99
+ current_plot_data = getattr (current_contrast , effect_attr )
100
+ bootstraps .append (current_plot_data .results .bootstraps [index ])
101
+ differences .append (current_plot_data .results .difference [index ])
102
+ bcalows .append (current_plot_data .results .bca_low [index ])
103
+ bcahighs .append (current_plot_data .results .bca_high [index ])
104
+ else :
105
+ msg1 = "There are only {} groups (starting from zero) in this dabest object. " .format (num_of_groups )
106
+ msg2 = "The idx given is {}." .format (index )
107
+ raise ValueError (msg1 + msg2 )
89
108
else :
90
109
contrast_plot_data = [getattr (getattr (contrast , effect_attr ), contrast_attr ) for contrast in data ]
91
-
92
110
attribute_suffix = "weighted_delta" if contrast_type == "mini_meta" else "delta_delta"
93
111
94
112
bootstraps = [getattr (result , f"bootstraps_{ attribute_suffix } " ) for result in contrast_plot_data ]
@@ -146,8 +164,8 @@ def check_for_errors(
146
164
if idx is not None :
147
165
if not isinstance (idx , (tuple , list )):
148
166
raise TypeError ("`idx` must be a tuple or list of integers." )
149
- if contrast_type == "mini_meta" :
150
- raise ValueError ("The `idx` argument is not applicable to mini-meta analyses." )
167
+ # if contrast_type == "mini_meta":
168
+ # raise ValueError("The `idx` argument is not applicable to mini-meta analyses.")
151
169
152
170
# Axes
153
171
if ax is not None and not isinstance (ax , plt .Axes ):
@@ -245,8 +263,8 @@ def get_kwargs(
245
263
violin_kwargs ,
246
264
zeroline_kwargs ,
247
265
horizontal ,
248
- es_marker_kwargs ,
249
- es_errorbar_kwargs ,
266
+ marker_kwargs ,
267
+ errorbar_kwargs ,
250
268
marker_size
251
269
):
252
270
from .misc_tools import merge_two_dicts
@@ -274,32 +292,32 @@ def get_kwargs(
274
292
zeroline_kwargs = merge_two_dicts (default_zeroline_kwargs , zeroline_kwargs )
275
293
276
294
# Effect size marker kwargs
277
- default_es_marker_kwargs = {
295
+ default_marker_kwargs = {
278
296
'marker' : 'o' ,
279
297
'markersize' : marker_size ,
280
298
'color' : 'black' ,
281
299
'alpha' : 1 ,
282
300
'zorder' : 2 ,
283
301
}
284
- if es_marker_kwargs is None :
285
- es_marker_kwargs = default_es_marker_kwargs
302
+ if marker_kwargs is None :
303
+ marker_kwargs = default_marker_kwargs
286
304
else :
287
- es_marker_kwargs = merge_two_dicts (default_es_marker_kwargs , es_marker_kwargs )
305
+ marker_kwargs = merge_two_dicts (default_marker_kwargs , marker_kwargs )
288
306
289
307
# Effect size error bar kwargs
290
- default_es_errorbar_kwargs = {
308
+ default_errorbar_kwargs = {
291
309
'color' : 'black' ,
292
310
'lw' : 2.5 ,
293
311
'linestyle' : '-' ,
294
312
'alpha' : 1 ,
295
313
'zorder' : 1 ,
296
314
}
297
- if es_errorbar_kwargs is None :
298
- es_errorbar_kwargs = default_es_errorbar_kwargs
315
+ if errorbar_kwargs is None :
316
+ errorbar_kwargs = default_errorbar_kwargs
299
317
else :
300
- es_errorbar_kwargs = merge_two_dicts (default_es_errorbar_kwargs , es_errorbar_kwargs )
318
+ errorbar_kwargs = merge_two_dicts (default_errorbar_kwargs , errorbar_kwargs )
301
319
302
- return violin_kwargs , zeroline_kwargs , es_marker_kwargs , es_errorbar_kwargs
320
+ return violin_kwargs , zeroline_kwargs , marker_kwargs , errorbar_kwargs
303
321
304
322
305
323
def color_palette (
@@ -355,8 +373,8 @@ def forest_plot(
355
373
356
374
violin_kwargs : Optional [dict ] = None ,
357
375
zeroline_kwargs : Optional [dict ] = None ,
358
- es_marker_kwargs : Optional [dict ] = None ,
359
- es_errorbar_kwargs : Optional [dict ] = None ,
376
+ marker_kwargs : Optional [dict ] = None ,
377
+ errorbar_kwargs : Optional [dict ] = None ,
360
378
)-> plt .Figure :
361
379
"""
362
380
Custom function that generates a forest plot from given contrast objects, suitable for a range of data analysis types, including those from packages like DABEST-python.
@@ -412,9 +430,9 @@ def forest_plot(
412
430
Additional arguments for violin plot customization.
413
431
zeroline_kwargs : Optional[dict], default=None
414
432
Additional arguments for the zero line customization.
415
- es_marker_kwargs : Optional[dict], default=None
433
+ marker_kwargs : Optional[dict], default=None
416
434
Additional arguments for the effect size marker customization.
417
- es_errorbar_kwargs : Optional[dict], default=None
435
+ errorbar_kwargs : Optional[dict], default=None
418
436
Additional arguments for the effect size error bar customization.
419
437
420
438
Returns
@@ -469,12 +487,12 @@ def forest_plot(
469
487
fig , ax = plt .subplots (figsize = fig_size )
470
488
471
489
# Get Kwargs
472
- violin_kwargs , zeroline_kwargs , es_marker_kwargs , es_errorbar_kwargs = get_kwargs (
490
+ violin_kwargs , zeroline_kwargs , marker_kwargs , errorbar_kwargs = get_kwargs (
473
491
violin_kwargs = violin_kwargs ,
474
492
zeroline_kwargs = zeroline_kwargs ,
475
493
horizontal = horizontal ,
476
- es_marker_kwargs = es_marker_kwargs ,
477
- es_errorbar_kwargs = es_errorbar_kwargs ,
494
+ marker_kwargs = marker_kwargs ,
495
+ errorbar_kwargs = errorbar_kwargs ,
478
496
marker_size = marker_size
479
497
)
480
498
@@ -492,11 +510,11 @@ def forest_plot(
492
510
## Plotting the effect sizes and confidence intervals
493
511
for k in range (1 , number_of_curves_to_plot + 1 ):
494
512
if horizontal :
495
- ax .plot (differences [k - 1 ], k , ** es_marker_kwargs )
496
- ax .plot ([bcalows [k - 1 ], bcahighs [k - 1 ]], [k , k ], ** es_errorbar_kwargs )
513
+ ax .plot (differences [k - 1 ], k , ** marker_kwargs )
514
+ ax .plot ([bcalows [k - 1 ], bcahighs [k - 1 ]], [k , k ], ** errorbar_kwargs )
497
515
else :
498
- ax .plot (k , differences [k - 1 ], ** es_marker_kwargs )
499
- ax .plot ([k , k ], [bcalows [k - 1 ], bcahighs [k - 1 ]], ** es_errorbar_kwargs )
516
+ ax .plot (k , differences [k - 1 ], ** marker_kwargs )
517
+ ax .plot ([k , k ], [bcalows [k - 1 ], bcahighs [k - 1 ]], ** errorbar_kwargs )
500
518
501
519
# Aesthetic Adjustments
502
520
## Handle the custom color palette
0 commit comments