Skip to content

Commit 8757b26

Browse files
committed
Bug fix for custom palette dictionary in delta delta use case
1 parent 79f2883 commit 8757b26

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

dabest/misc_tools.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def get_color_palette(
481481
xvar: str,
482482
show_pairs: bool,
483483
idx: list,
484-
all_plot_groups: list
484+
all_plot_groups: list,
485+
delta2: bool,
485486
):
486487
"""
487488
Create the color palette to be used in the plotter function.
@@ -500,6 +501,8 @@ def get_color_palette(
500501
A list of tuples containing the group names.
501502
all_plot_groups : list
502503
A list of all the group names.
504+
delta2 : bool
505+
A boolean flag to determine if the plot will have a delta-delta effect size.
503506
"""
504507
# Create color palette that will be shared across subplots.
505508
color_col = plot_kwargs["color_col"]
@@ -550,9 +553,16 @@ def get_color_palette(
550553
unsat_colors = [sns.color_palette("gray")[3]] + unsat_colors
551554
else:
552555
if isinstance(custom_pal, dict):
553-
groups_in_palette = {
554-
k: custom_pal[k] for k in all_plot_groups if k in color_groups
555-
}
556+
if delta2:
557+
groups_in_palette = {
558+
k: custom_pal[k] for k in color_groups
559+
}
560+
elif color_col is None:
561+
groups_in_palette = {
562+
k: custom_pal[k] for k in all_plot_groups if k in color_groups
563+
}
564+
else:
565+
raise ValueError("The `custom_palette` dictionary is not supported when `color_col` is None.")
556566

557567
names = groups_in_palette.keys()
558568
unsat_colors = groups_in_palette.values()

dabest/plotter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
151151
xvar = xvar,
152152
show_pairs = show_pairs,
153153
idx = idx,
154-
all_plot_groups = all_plot_groups
154+
all_plot_groups = all_plot_groups,
155+
delta2 = effectsize_df.delta2
155156
)
156157

157158
# Initialise the figure.

nbs/API/misc_tools.ipynb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@
534534
" xvar: str, \n",
535535
" show_pairs: bool, \n",
536536
" idx: list, \n",
537-
" all_plot_groups: list\n",
537+
" all_plot_groups: list,\n",
538+
" delta2: bool,\n",
538539
" ):\n",
539540
" \"\"\"\n",
540541
" Create the color palette to be used in the plotter function.\n",
@@ -553,6 +554,8 @@
553554
" A list of tuples containing the group names.\n",
554555
" all_plot_groups : list\n",
555556
" A list of all the group names.\n",
557+
" delta2 : bool\n",
558+
" A boolean flag to determine if the plot will have a delta-delta effect size.\n",
556559
" \"\"\"\n",
557560
" # Create color palette that will be shared across subplots.\n",
558561
" color_col = plot_kwargs[\"color_col\"]\n",
@@ -603,9 +606,16 @@
603606
" unsat_colors = [sns.color_palette(\"gray\")[3]] + unsat_colors\n",
604607
" else:\n",
605608
" if isinstance(custom_pal, dict):\n",
606-
" groups_in_palette = {\n",
607-
" k: custom_pal[k] for k in all_plot_groups if k in color_groups\n",
608-
" }\n",
609+
" if delta2:\n",
610+
" groups_in_palette = {\n",
611+
" k: custom_pal[k] for k in color_groups\n",
612+
" }\n",
613+
" elif color_col is None:\n",
614+
" groups_in_palette = {\n",
615+
" k: custom_pal[k] for k in all_plot_groups if k in color_groups\n",
616+
" }\n",
617+
" else:\n",
618+
" raise ValueError(\"The `custom_palette` dictionary is not supported when `color_col` is None.\")\n",
609619
"\n",
610620
" names = groups_in_palette.keys()\n",
611621
" unsat_colors = groups_in_palette.values()\n",

nbs/API/plotter.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@
208208
" xvar = xvar, \n",
209209
" show_pairs = show_pairs,\n",
210210
" idx = idx,\n",
211-
" all_plot_groups = all_plot_groups\n",
211+
" all_plot_groups = all_plot_groups,\n",
212+
" delta2 = effectsize_df.delta2\n",
212213
" )\n",
213214
"\n",
214215
" # Initialise the figure.\n",

0 commit comments

Comments
 (0)