Skip to content

Commit d254128

Browse files
committed
fixed color selector for contrast and swarm bars to work properly with paired but show_pairs=False
1 parent b2e4dab commit d254128

12 files changed

Lines changed: 89 additions & 68 deletions

dabest/plot_tools.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def sankeydiag(
875875
def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object,
876876
float_contrast: bool,summary_bars_kwargs: dict, ci_type: str,
877877
ticks_to_plot: list, color_col: str, plot_palette_raw: dict,
878-
proportional: bool, is_paired: bool, horizontal: bool):
878+
proportional: bool, show_pairs: bool, horizontal: bool):
879879
"""
880880
Add summary bars to the contrast plot. Currently only functional for Vertical plots.
881881
@@ -901,8 +901,8 @@ def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object
901901
Dictionary of colors used in the plot.
902902
proportional : bool
903903
Whether the data is proportional.
904-
is_paired : bool
905-
Whether the data is paired.
904+
show_pairs : bool
905+
Whether the data is paired and shown in pairs.
906906
horizontal : bool
907907
Whether the plot is horizontal.
908908
"""
@@ -924,7 +924,7 @@ def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object
924924
[summary_bars_kwargs.get('color')]*int(max(ticks_to_plot)+1)
925925
if summary_bars_kwargs.get('color') is not None
926926
else ['black']*int(max(ticks_to_plot)+1)
927-
if color_col is not None or (proportional and is_paired) or is_paired
927+
if color_col is not None or (proportional and show_pairs) or show_pairs
928928
else list(plot_palette_raw.values())
929929
)
930930
summary_bars_kwargs.pop('color')
@@ -963,7 +963,7 @@ def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object
963963
def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object,
964964
ticks_to_plot: list, contrast_bars_kwargs: dict, color_col: str,
965965
plot_palette_raw: dict, show_mini_meta: bool, mini_meta_delta: object,
966-
show_delta2: bool, delta_delta: object, is_paired: bool,
966+
show_delta2: bool, delta_delta: object, show_pairs: bool,
967967
horizontal: bool, idx: list):
968968
"""
969969
Add contrast bars to the contrast plot.
@@ -992,8 +992,8 @@ def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: o
992992
Whether to show the delta-delta.
993993
delta_delta : object
994994
delta-delta object.
995-
is_paired : bool
996-
Whether the data is paired.
995+
show_pairs : bool
996+
Whether the data is paired and shown in pairs.
997997
horizontal : bool
998998
Whether the plot is horizontal.
999999
idx : list
@@ -1012,13 +1012,13 @@ def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: o
10121012
[contrast_bars_kwargs.get('color')] * int(max(ticks_to_plot) + 1)
10131013
if contrast_bars_kwargs.get('color') is not None
10141014
else ['black'] * int(max(ticks_to_plot) + 1)
1015-
if color_col is not None or is_paired
1015+
if color_col is not None or show_pairs
10161016
else plot_palette_raw
10171017
)
10181018
contrast_bars_kwargs.pop('color')
10191019

10201020
# alpha
1021-
contrast_bars_kwargs['alpha'] = contrast_bars_kwargs.get('alpha', 0.15 if color_col is not None or is_paired else 0.25)
1021+
contrast_bars_kwargs['alpha'] = contrast_bars_kwargs.get('alpha', 0.15 if color_col is not None or show_pairs else 0.25)
10221022

10231023
for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):
10241024
idx_selector = (
@@ -1043,7 +1043,7 @@ def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: o
10431043

10441044
def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,
10451045
swarm_bars_kwargs: dict, color_col: str, plot_palette_raw: dict,
1046-
is_paired: bool, idx: list):
1046+
show_pairs: bool, idx: list):
10471047
"""
10481048
Add bars to the raw data plot. Currently only for vertical plots.
10491049
@@ -1063,8 +1063,8 @@ def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,
10631063
Column name of the color column.
10641064
plot_palette_raw : dict
10651065
Dictionary of colors used in the plot.
1066-
is_paired : bool
1067-
Whether the data is paired.
1066+
show_pairs : bool
1067+
Whether the data is paired and shown in pairs.
10681068
idx : list
10691069
List of indices of the raw groups.
10701070
"""
@@ -1084,13 +1084,13 @@ def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,
10841084
[swarm_bars_kwargs.get('color')] * (len(swarm_bars_order) + 1)
10851085
if swarm_bars_kwargs.get('color') is not None
10861086
else ['black']*(len(swarm_bars_order)+1)
1087-
if color_col is not None or is_paired
1087+
if color_col is not None or show_pairs
10881088
else plot_palette_raw
10891089
)
10901090
swarm_bars_kwargs.pop('color')
10911091

10921092
# alpha
1093-
swarm_bars_kwargs['alpha'] = swarm_bars_kwargs.get('alpha', 0.15 if color_col is not None or is_paired else 0.25)
1093+
swarm_bars_kwargs['alpha'] = swarm_bars_kwargs.get('alpha', 0.15 if color_col is not None or show_pairs else 0.25)
10941094

10951095
for swarm_bars_x,swarm_bars_y in zip(np.arange(0,len(swarm_bars_order)+1,1), swarm_means):
10961096
idx_selector = (

dabest/plotter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
479479
swarm_bars_kwargs = swarm_bars_kwargs,
480480
color_col = color_col,
481481
plot_palette_raw = plot_palette_raw,
482-
is_paired = is_paired,
482+
show_pairs = show_pairs,
483483
idx = idx,
484484
)
485485

@@ -498,7 +498,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
498498
mini_meta_delta = effectsize_df.mini_meta_delta if show_mini_meta else None,
499499
show_delta2 = show_delta2,
500500
delta_delta = effectsize_df.delta_delta if show_delta2 else None,
501-
is_paired = is_paired,
501+
show_pairs = show_pairs,
502502
horizontal = horizontal,
503503
idx = idx
504504
)
@@ -517,7 +517,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
517517
color_col = color_col,
518518
plot_palette_raw = plot_palette_raw,
519519
proportional = proportional,
520-
is_paired = is_paired,
520+
show_pairs = show_pairs,
521521
horizontal = horizontal,
522522
)
523523
# Delta text

nbs/API/plot_tools.ipynb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@
925925
"def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object,\n",
926926
" float_contrast: bool,summary_bars_kwargs: dict, ci_type: str,\n",
927927
" ticks_to_plot: list, color_col: str, plot_palette_raw: dict, \n",
928-
" proportional: bool, is_paired: bool, horizontal: bool):\n",
928+
" proportional: bool, show_pairs: bool, horizontal: bool):\n",
929929
" \"\"\"\n",
930930
" Add summary bars to the contrast plot. Currently only functional for Vertical plots.\n",
931931
"\n",
@@ -951,8 +951,8 @@
951951
" Dictionary of colors used in the plot.\n",
952952
" proportional : bool\n",
953953
" Whether the data is proportional.\n",
954-
" is_paired : bool\n",
955-
" Whether the data is paired.\n",
954+
" show_pairs : bool\n",
955+
" Whether the data is paired and shown in pairs.\n",
956956
" horizontal : bool\n",
957957
" Whether the plot is horizontal.\n",
958958
" \"\"\"\n",
@@ -974,7 +974,7 @@
974974
" [summary_bars_kwargs.get('color')]*int(max(ticks_to_plot)+1)\n",
975975
" if summary_bars_kwargs.get('color') is not None\n",
976976
" else ['black']*int(max(ticks_to_plot)+1)\n",
977-
" if color_col is not None or (proportional and is_paired) or is_paired \n",
977+
" if color_col is not None or (proportional and show_pairs) or show_pairs \n",
978978
" else list(plot_palette_raw.values())\n",
979979
" )\n",
980980
" summary_bars_kwargs.pop('color')\n",
@@ -1013,7 +1013,7 @@
10131013
"def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object,\n",
10141014
" ticks_to_plot: list, contrast_bars_kwargs: dict, color_col: str, \n",
10151015
" plot_palette_raw: dict, show_mini_meta: bool, mini_meta_delta: object, \n",
1016-
" show_delta2: bool, delta_delta: object, is_paired: bool,\n",
1016+
" show_delta2: bool, delta_delta: object, show_pairs: bool,\n",
10171017
" horizontal: bool, idx: list):\n",
10181018
" \"\"\"\n",
10191019
" Add contrast bars to the contrast plot.\n",
@@ -1042,8 +1042,8 @@
10421042
" Whether to show the delta-delta.\n",
10431043
" delta_delta : object\n",
10441044
" delta-delta object.\n",
1045-
" is_paired : bool\n",
1046-
" Whether the data is paired.\n",
1045+
" show_pairs : bool\n",
1046+
" Whether the data is paired and shown in pairs.\n",
10471047
" horizontal : bool\n",
10481048
" Whether the plot is horizontal.\n",
10491049
" idx : list\n",
@@ -1062,13 +1062,13 @@
10621062
" [contrast_bars_kwargs.get('color')] * int(max(ticks_to_plot) + 1) \n",
10631063
" if contrast_bars_kwargs.get('color') is not None \n",
10641064
" else ['black'] * int(max(ticks_to_plot) + 1) \n",
1065-
" if color_col is not None or is_paired \n",
1065+
" if color_col is not None or show_pairs\n",
10661066
" else plot_palette_raw\n",
10671067
" )\n",
10681068
" contrast_bars_kwargs.pop('color')\n",
10691069
"\n",
10701070
" # alpha\n",
1071-
" contrast_bars_kwargs['alpha'] = contrast_bars_kwargs.get('alpha', 0.15 if color_col is not None or is_paired else 0.25)\n",
1071+
" contrast_bars_kwargs['alpha'] = contrast_bars_kwargs.get('alpha', 0.15 if color_col is not None or show_pairs else 0.25)\n",
10721072
"\n",
10731073
" for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):\n",
10741074
" idx_selector = (\n",
@@ -1093,7 +1093,7 @@
10931093
"\n",
10941094
"def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,\n",
10951095
" swarm_bars_kwargs: dict, color_col: str, plot_palette_raw: dict, \n",
1096-
" is_paired: bool, idx: list):\n",
1096+
" show_pairs: bool, idx: list):\n",
10971097
" \"\"\"\n",
10981098
" Add bars to the raw data plot. Currently only for vertical plots.\n",
10991099
"\n",
@@ -1113,8 +1113,8 @@
11131113
" Column name of the color column.\n",
11141114
" plot_palette_raw : dict\n",
11151115
" Dictionary of colors used in the plot.\n",
1116-
" is_paired : bool\n",
1117-
" Whether the data is paired.\n",
1116+
" show_pairs : bool\n",
1117+
" Whether the data is paired and shown in pairs.\n",
11181118
" idx : list\n",
11191119
" List of indices of the raw groups.\n",
11201120
" \"\"\"\n",
@@ -1134,13 +1134,13 @@
11341134
" [swarm_bars_kwargs.get('color')] * (len(swarm_bars_order) + 1) \n",
11351135
" if swarm_bars_kwargs.get('color') is not None \n",
11361136
" else ['black']*(len(swarm_bars_order)+1)\n",
1137-
" if color_col is not None or is_paired\n",
1137+
" if color_col is not None or show_pairs\n",
11381138
" else plot_palette_raw\n",
11391139
" )\n",
11401140
" swarm_bars_kwargs.pop('color')\n",
11411141
"\n",
11421142
" # alpha\n",
1143-
" swarm_bars_kwargs['alpha'] = swarm_bars_kwargs.get('alpha', 0.15 if color_col is not None or is_paired else 0.25)\n",
1143+
" swarm_bars_kwargs['alpha'] = swarm_bars_kwargs.get('alpha', 0.15 if color_col is not None or show_pairs else 0.25)\n",
11441144
"\n",
11451145
" for swarm_bars_x,swarm_bars_y in zip(np.arange(0,len(swarm_bars_order)+1,1), swarm_means):\n",
11461146
" idx_selector = (\n",

nbs/API/plotter.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@
536536
" swarm_bars_kwargs = swarm_bars_kwargs, \n",
537537
" color_col = color_col, \n",
538538
" plot_palette_raw = plot_palette_raw,\n",
539-
" is_paired = is_paired,\n",
539+
" show_pairs = show_pairs,\n",
540540
" idx = idx,\n",
541541
" )\n",
542542
"\n",
@@ -555,7 +555,7 @@
555555
" mini_meta_delta = effectsize_df.mini_meta_delta if show_mini_meta else None, \n",
556556
" show_delta2 = show_delta2, \n",
557557
" delta_delta = effectsize_df.delta_delta if show_delta2 else None, \n",
558-
" is_paired = is_paired,\n",
558+
" show_pairs = show_pairs,\n",
559559
" horizontal = horizontal,\n",
560560
" idx = idx\n",
561561
" )\n",
@@ -574,7 +574,7 @@
574574
" color_col = color_col,\n",
575575
" plot_palette_raw = plot_palette_raw, \n",
576576
" proportional = proportional, \n",
577-
" is_paired = is_paired,\n",
577+
" show_pairs = show_pairs,\n",
578578
" horizontal = horizontal,\n",
579579
" )\n",
580580
" # Delta text\n",
81 Bytes
Loading
559 Bytes
Loading

nbs/tutorials/01-basics.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
"==================\n",
342342
" \n",
343343
"Good morning!\n",
344-
"The current time is Wed Dec 4 11:17:13 2024.\n",
344+
"The current time is Wed Dec 4 11:40:47 2024.\n",
345345
"\n",
346346
"Effect size(s) with 95% confidence intervals will be computed for:\n",
347347
"1. Test 1 minus Control 1\n",
@@ -406,7 +406,7 @@
406406
"==================\n",
407407
" \n",
408408
"Good morning!\n",
409-
"The current time is Wed Dec 4 11:17:13 2024.\n",
409+
"The current time is Wed Dec 4 11:40:47 2024.\n",
410410
"\n",
411411
"Effect size(s) with 90% confidence intervals will be computed for:\n",
412412
"1. Test 1 minus Control 1\n",
@@ -463,7 +463,7 @@
463463
"==================\n",
464464
" \n",
465465
"Good morning!\n",
466-
"The current time is Wed Dec 4 11:17:13 2024.\n",
466+
"The current time is Wed Dec 4 11:40:47 2024.\n",
467467
"\n",
468468
"The unpaired mean difference between Control 1 and Test 1 is 0.48 [95%CI 0.221, 0.768].\n",
469469
"The p-value of the two-sided permutation t-test is 0.001, calculated for legacy purposes only. \n",
@@ -747,7 +747,7 @@
747747
"==================\n",
748748
" \n",
749749
"Good morning!\n",
750-
"The current time is Wed Dec 4 11:17:13 2024.\n",
750+
"The current time is Wed Dec 4 11:40:48 2024.\n",
751751
"\n",
752752
"The unpaired Hedges' g between Control 1 and Test 1 is 1.03 [95%CI 0.349, 1.62].\n",
753753
"The p-value of the two-sided permutation t-test is 0.001, calculated for legacy purposes only. \n",
@@ -1086,7 +1086,7 @@
10861086
"==================\n",
10871087
" \n",
10881088
"Good morning!\n",
1089-
"The current time is Wed Dec 4 11:17:14 2024.\n",
1089+
"The current time is Wed Dec 4 11:40:49 2024.\n",
10901090
"\n",
10911091
"Effect size(s) with 95% confidence intervals will be computed for:\n",
10921092
"1. Test 1 minus Control 1\n",
@@ -1121,7 +1121,7 @@
11211121
"==================\n",
11221122
" \n",
11231123
"Good morning!\n",
1124-
"The current time is Wed Dec 4 11:17:16 2024.\n",
1124+
"The current time is Wed Dec 4 11:40:50 2024.\n",
11251125
"\n",
11261126
"The unpaired mean difference between Control 1 and Test 1 is 0.48 [95%CI 0.221, 0.768].\n",
11271127
"The p-value of the two-sided permutation t-test is 0.001, calculated for legacy purposes only. \n",
@@ -1222,7 +1222,7 @@
12221222
"==================\n",
12231223
" \n",
12241224
"Good morning!\n",
1225-
"The current time is Wed Dec 4 11:17:16 2024.\n",
1225+
"The current time is Wed Dec 4 11:40:50 2024.\n",
12261226
"\n",
12271227
"Effect size(s) with 95% confidence intervals will be computed for:\n",
12281228
"1. Test 1 minus Control 1\n",
@@ -1257,7 +1257,7 @@
12571257
"==================\n",
12581258
" \n",
12591259
"Good morning!\n",
1260-
"The current time is Wed Dec 4 11:17:17 2024.\n",
1260+
"The current time is Wed Dec 4 11:40:51 2024.\n",
12611261
"\n",
12621262
"The unpaired mean difference between Control 1 and Test 1 is 0.48 [95%CI 0.221, 0.768].\n",
12631263
"The p-value of the two-sided permutation t-test is 0.001, calculated for legacy purposes only. \n",
@@ -1469,7 +1469,7 @@
14691469
"==================\n",
14701470
" \n",
14711471
"Good morning!\n",
1472-
"The current time is Wed Dec 4 11:17:18 2024.\n",
1472+
"The current time is Wed Dec 4 11:40:52 2024.\n",
14731473
"\n",
14741474
"Effect size(s) with 95% confidence intervals will be computed for:\n",
14751475
"1. Test 1 minus Control 1\n",

nbs/tutorials/02-repeated_measures.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"==================\n",
159159
" \n",
160160
"Good morning!\n",
161-
"The current time is Wed Dec 4 11:17:17 2024.\n",
161+
"The current time is Wed Dec 4 11:40:57 2024.\n",
162162
"\n",
163163
"Paired effect size(s) for the sequential design of repeated-measures experiment \n",
164164
"with 95% confidence intervals will be computed for:\n",
@@ -209,7 +209,7 @@
209209
"==================\n",
210210
" \n",
211211
"Good morning!\n",
212-
"The current time is Wed Dec 4 11:17:17 2024.\n",
212+
"The current time is Wed Dec 4 11:40:57 2024.\n",
213213
"\n",
214214
"Paired effect size(s) for repeated measures against baseline \n",
215215
"with 95% confidence intervals will be computed for:\n",
@@ -248,7 +248,7 @@
248248
"==================\n",
249249
" \n",
250250
"Good morning!\n",
251-
"The current time is Wed Dec 4 11:17:17 2024.\n",
251+
"The current time is Wed Dec 4 11:40:58 2024.\n",
252252
"\n",
253253
"The paired mean difference for the sequential design of repeated-measures experiment \n",
254254
"between Control 1 and Test 1 is 0.48 [95%CI 0.237, 0.73].\n",
@@ -284,7 +284,7 @@
284284
"==================\n",
285285
" \n",
286286
"Good morning!\n",
287-
"The current time is Wed Dec 4 11:17:17 2024.\n",
287+
"The current time is Wed Dec 4 11:40:58 2024.\n",
288288
"\n",
289289
"The paired mean difference for repeated measures against baseline \n",
290290
"between Control 1 and Test 1 is 0.48 [95%CI 0.237, 0.73].\n",
@@ -443,7 +443,7 @@
443443
"==================\n",
444444
" \n",
445445
"Good morning!\n",
446-
"The current time is Wed Dec 4 11:17:19 2024.\n",
446+
"The current time is Wed Dec 4 11:41:00 2024.\n",
447447
"\n",
448448
"The paired mean difference for the sequential design of repeated-measures experiment \n",
449449
"between Control 1 and Test 1 is 0.48 [95%CI 0.237, 0.73].\n",
@@ -528,7 +528,7 @@
528528
"==================\n",
529529
" \n",
530530
"Good morning!\n",
531-
"The current time is Wed Dec 4 11:17:20 2024.\n",
531+
"The current time is Wed Dec 4 11:41:01 2024.\n",
532532
"\n",
533533
"The paired mean difference for repeated measures against baseline \n",
534534
"between Control 1 and Test 1 is 0.48 [95%CI 0.237, 0.73].\n",

0 commit comments

Comments
 (0)