Skip to content

Commit a4960a5

Browse files
committed
Added swarm_side for choosing of asymmetric side
1 parent feac638 commit a4960a5

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

dabest/plotter.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,9 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
547547
delta_df[yvar] = temp_df_exp[yvar] - temp_df_cont[yvar]
548548
final_deltas = pd.concat([final_deltas, delta_df])
549549

550-
# Change jitter for Gardner-Altman plot
550+
# swarmplot() plots swarms based on current size of ax
551+
# Therefore, since the ax size for Gardner-Altman plot changes later on, there has to be decreased jitter
552+
# TODO: to make jitter value more accurate and not just a hardcoded eyeball value
551553
if float_contrast:
552554
jitter = 0.6
553555
else:
@@ -627,7 +629,13 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
627629
else:
628630
if not proportional:
629631
# Plot the raw data as a swarmplot.
630-
asymmetric_side = "right"
632+
asymmetric_side = (
633+
plot_kwargs["swarm_side"] if plot_kwargs["swarm_side"] is not None else "right"
634+
) # Default asymmetric side is right
635+
636+
# swarmplot() plots swarms based on current size of ax
637+
# Therefore, since the ax size for mini_meta and show_delta changes later on, there has to be increased jitter
638+
# TODO: to make jitter value more accurate and not just a hardcoded eyeball value
631639
if show_mini_meta:
632640
jitter = 1.25
633641
elif show_delta2:
@@ -698,6 +706,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
698706
for jj, c in enumerate(rawdata_axes.collections):
699707
try:
700708
if asymmetric_side == "right":
709+
# currently offset is hardcoded with value of -0.2
701710
x_max_span = -0.2
702711
else:
703712
_, x_max, _, _ = get_swarm_spans(c)

nbs/API/plotter.ipynb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@
606606
" delta_df[yvar] = temp_df_exp[yvar] - temp_df_cont[yvar]\n",
607607
" final_deltas = pd.concat([final_deltas, delta_df])\n",
608608
"\n",
609-
" # Change jitter for Gardner-Altman plot\n",
609+
" # swarmplot() plots swarms based on current size of ax\n",
610+
" # Therefore, since the ax size for Gardner-Altman plot changes later on, there has to be decreased jitter\n",
611+
" # TODO: to make jitter value more accurate and not just a hardcoded eyeball value\n",
610612
" if float_contrast:\n",
611613
" jitter = 0.6\n",
612614
" else:\n",
@@ -686,7 +688,13 @@
686688
" else:\n",
687689
" if not proportional:\n",
688690
" # Plot the raw data as a swarmplot.\n",
689-
" asymmetric_side = \"right\"\n",
691+
" asymmetric_side = (\n",
692+
" plot_kwargs[\"swarm_side\"] if plot_kwargs[\"swarm_side\"] is not None else \"right\"\n",
693+
" ) # Default asymmetric side is right\n",
694+
"\n",
695+
" # swarmplot() plots swarms based on current size of ax\n",
696+
" # Therefore, since the ax size for mini_meta and show_delta changes later on, there has to be increased jitter\n",
697+
" # TODO: to make jitter value more accurate and not just a hardcoded eyeball value\n",
690698
" if show_mini_meta:\n",
691699
" jitter = 1.25\n",
692700
" elif show_delta2:\n",
@@ -757,6 +765,7 @@
757765
" for jj, c in enumerate(rawdata_axes.collections):\n",
758766
" try:\n",
759767
" if asymmetric_side == \"right\":\n",
768+
" # currently offset is hardcoded with value of -0.2\n",
760769
" x_max_span = -0.2\n",
761770
" else:\n",
762771
" _, x_max, _, _ = get_swarm_spans(c)\n",

0 commit comments

Comments
 (0)