Skip to content

Commit cf5676f

Browse files
Jacobluke-JAnns98
authored andcommitted
Finalize unpaired prop plot color issue
1 parent b0cf864 commit cf5676f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

dabest/plot_tools.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,26 @@ def barplotter(
21082108
else:
21092109
x_var, y_var, orient = all_plot_groups, np.ones(len(all_plot_groups)), "v"
21102110

2111-
bar1_df = pd.DataFrame({xvar: x_var, "proportion": y_var})
2111+
# Create bar1_df with basic columns
2112+
bar1_df = pd.DataFrame({
2113+
xvar: x_var,
2114+
"proportion": y_var
2115+
})
2116+
2117+
# Handle colors
2118+
if color_col:
2119+
# Get first color value for each group
2120+
color_mapping = plot_data.groupby(xvar, observed=False)[color_col].first()
2121+
bar1_df[color_col] = [color_mapping.get(group) for group in all_plot_groups]
2122+
2123+
# Map colors, defaulting to bar_color if no match
2124+
edge_colors = [
2125+
plot_palette_bar.get(hue_val, bar_color)
2126+
for hue_val in bar1_df[color_col]
2127+
]
2128+
else:
2129+
edge_colors = bar_color
2130+
21122131

21132132
bar1 = sns.barplot(
21142133
data=bar1_df,
@@ -2118,7 +2137,7 @@ def barplotter(
21182137
order=all_plot_groups,
21192138
linewidth=2,
21202139
facecolor=(1, 1, 1, 0),
2121-
edgecolor=bar_color,
2140+
edgecolor=edge_colors,
21222141
zorder=1,
21232142
orient=orient,
21242143
)

0 commit comments

Comments
 (0)