Skip to content

Commit d0fe414

Browse files
committed
Fix bug for non-string cols and deprecation in sns
Fix the bug #108 where non-string column names are supplied in DABEST usages by coordinating with the deprecation of providing only ‘palette’ with no ‘hue’
1 parent 1377394 commit d0fe414

2 files changed

Lines changed: 60 additions & 23 deletions

File tree

dabest/plotter.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -604,17 +604,31 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
604604
else:
605605
if not proportional:
606606
# Plot the raw data as a swarmplot.
607-
rawdata_plot = sns.swarmplot(
608-
data=plot_data,
609-
x=xvar,
610-
y=yvar,
611-
ax=rawdata_axes,
612-
order=all_plot_groups,
613-
hue=color_col,
614-
palette=plot_palette_raw,
615-
zorder=1,
616-
**swarmplot_kwargs
617-
)
607+
if color_col is None: # Determine the use of hue
608+
rawdata_plot = sns.swarmplot(
609+
data=plot_data,
610+
x=xvar,
611+
y=yvar,
612+
ax=rawdata_axes,
613+
order=all_plot_groups,
614+
hue=xvar,
615+
palette=plot_palette_raw,
616+
zorder=1,
617+
**swarmplot_kwargs
618+
)
619+
rawdata_plot.legend().set_visible(False)
620+
else:
621+
rawdata_plot = sns.swarmplot(
622+
data=plot_data,
623+
x=xvar,
624+
y=yvar,
625+
ax=rawdata_axes,
626+
order=all_plot_groups,
627+
hue=color_col,
628+
palette=plot_palette_raw,
629+
zorder=1,
630+
**swarmplot_kwargs
631+
)
618632
else:
619633
# Plot the raw data as a barplot.
620634
bar1_df = pd.DataFrame(
@@ -672,6 +686,10 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
672686
if bootstraps_color_by_group:
673687
line_colors.append(plot_palette_raw[all_plot_groups[jj]])
674688

689+
# Break the loop since hue in Seaborn adds collections to axes and it will result in index out of range
690+
if jj >= n_groups - 1 and color_col is None:
691+
break
692+
675693
if len(line_colors) != len(all_plot_groups):
676694
line_colors = ytick_color
677695

@@ -1534,3 +1552,4 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
15341552

15351553
# Return the figure.
15361554
return fig
1555+

nbs/API/plotter.ipynb

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,17 +663,31 @@
663663
" else:\n",
664664
" if not proportional:\n",
665665
" # Plot the raw data as a swarmplot.\n",
666-
" rawdata_plot = sns.swarmplot(\n",
667-
" data=plot_data,\n",
668-
" x=xvar,\n",
669-
" y=yvar,\n",
670-
" ax=rawdata_axes,\n",
671-
" order=all_plot_groups,\n",
672-
" hue=color_col,\n",
673-
" palette=plot_palette_raw,\n",
674-
" zorder=1,\n",
675-
" **swarmplot_kwargs\n",
676-
" )\n",
666+
" if color_col is None: # Determine the use of hue\n",
667+
" rawdata_plot = sns.swarmplot(\n",
668+
" data=plot_data,\n",
669+
" x=xvar,\n",
670+
" y=yvar,\n",
671+
" ax=rawdata_axes,\n",
672+
" order=all_plot_groups,\n",
673+
" hue=xvar,\n",
674+
" palette=plot_palette_raw,\n",
675+
" zorder=1,\n",
676+
" **swarmplot_kwargs\n",
677+
" )\n",
678+
" rawdata_plot.legend().set_visible(False)\n",
679+
" else:\n",
680+
" rawdata_plot = sns.swarmplot(\n",
681+
" data=plot_data,\n",
682+
" x=xvar,\n",
683+
" y=yvar,\n",
684+
" ax=rawdata_axes,\n",
685+
" order=all_plot_groups,\n",
686+
" hue=color_col,\n",
687+
" palette=plot_palette_raw,\n",
688+
" zorder=1,\n",
689+
" **swarmplot_kwargs\n",
690+
" )\n",
677691
" else:\n",
678692
" # Plot the raw data as a barplot.\n",
679693
" bar1_df = pd.DataFrame(\n",
@@ -731,6 +745,10 @@
731745
" if bootstraps_color_by_group:\n",
732746
" line_colors.append(plot_palette_raw[all_plot_groups[jj]])\n",
733747
"\n",
748+
" # Break the loop since hue in Seaborn adds collections to axes and it will result in index out of range\n",
749+
" if jj >= n_groups - 1 and color_col is None:\n",
750+
" break\n",
751+
"\n",
734752
" if len(line_colors) != len(all_plot_groups):\n",
735753
" line_colors = ytick_color\n",
736754
"\n",
@@ -1592,7 +1610,7 @@
15921610
" plt.rcParams[parameter] = original_rcParams[parameter]\n",
15931611
"\n",
15941612
" # Return the figure.\n",
1595-
" return fig"
1613+
" return fig\n"
15961614
]
15971615
},
15981616
{

0 commit comments

Comments
 (0)