Skip to content

Commit afe3f01

Browse files
committed
Fixed color palette bug ordering if melted format data and the idx is not in order with the dataframe itself
1 parent e6dfe38 commit afe3f01

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

dabest/misc_tools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def get_unique_categories(names):
8686
"""
8787
Extract unique categories from various input types.
8888
"""
89+
if isinstance(names, list):
90+
return names
8991
if isinstance(names, np.ndarray):
9092
return names # numpy.unique() returns a sorted array
9193
elif isinstance(names, (pd.Categorical, pd.Series)):
@@ -546,7 +548,11 @@ def get_color_palette(
546548
filled.append(False)
547549
filled.extend([True] * (len(idx[i]) - 1))
548550

549-
names = color_groups if not color_by_subgroups else idx
551+
if color_col is not None:
552+
names = color_groups if not color_by_subgroups else idx
553+
else:
554+
names = all_plot_groups if not color_by_subgroups else idx
555+
550556
n_groups = len(color_groups)
551557
custom_pal = plot_kwargs["custom_palette"]
552558
swarm_desat = plot_kwargs["swarm_desat"]

nbs/API/misc_tools.ipynb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
" \"\"\"\n",
140140
" Extract unique categories from various input types.\n",
141141
" \"\"\"\n",
142+
" if isinstance(names, list):\n",
143+
" return names\n",
142144
" if isinstance(names, np.ndarray):\n",
143145
" return names # numpy.unique() returns a sorted array\n",
144146
" elif isinstance(names, (pd.Categorical, pd.Series)):\n",
@@ -599,7 +601,11 @@
599601
" filled.append(False)\n",
600602
" filled.extend([True] * (len(idx[i]) - 1))\n",
601603
"\n",
602-
" names = color_groups if not color_by_subgroups else idx\n",
604+
" if color_col is not None:\n",
605+
" names = color_groups if not color_by_subgroups else idx\n",
606+
" else:\n",
607+
" names = all_plot_groups if not color_by_subgroups else idx\n",
608+
"\n",
603609
" n_groups = len(color_groups)\n",
604610
" custom_pal = plot_kwargs[\"custom_palette\"]\n",
605611
" swarm_desat = plot_kwargs[\"swarm_desat\"]\n",

0 commit comments

Comments
 (0)