Skip to content

Commit 41306f5

Browse files
committed
Added changes From Sangyu's PR for gridkey auto parser
1 parent 29a1e11 commit 41306f5

File tree

8 files changed

+76
-16
lines changed

8 files changed

+76
-16
lines changed

dabest/_effsize_objects.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ def plot(
10011001
gridkey_merge_pairs=False,
10021002
gridkey_show_Ns=True,
10031003
gridkey_show_es=True,
1004+
gridkey_delimiters=[';', '>', '_'],
10041005
swarmplot_kwargs=None,
10051006
barplot_kwargs=None,
10061007
violinplot_kwargs=None,
@@ -1122,7 +1123,18 @@ def plot(
11221123
gridkey_rows : list, default None
11231124
Provide a list of row labels for the gridkey. The supplied idx is
11241125
checked against the row labels to determine whether the corresponding
1125-
cell should be populated or not.
1126+
cell should be populated or not.
1127+
This can also be set to "auto", which will attempt to auto populate the table.
1128+
gridkey_merge_pairs : boolean, default False
1129+
If True, the gridkey will merge the pairs of groups into a single
1130+
cell. This is useful for when the groups are paired.
1131+
gridkey_show_Ns : boolean, default True
1132+
If True, the gridkey will show the number of observations in each
1133+
group.
1134+
gridkey_show_es : boolean, default True
1135+
If True, the gridkey will show the effect size of each comparison.
1136+
gridkey_delimiters : list, default [';', '>', '_']
1137+
The delimiters used to separate the group names in the gridkey.
11261138
swarmplot_kwargs : dict, default None
11271139
Pass any keyword arguments accepted by the seaborn `swarmplot`
11281140
command here, as a dict. If None, the following keywords are
@@ -1180,7 +1192,6 @@ def plot(
11801192
fontsize_delta2label : float, default 12
11811193
Font size for the delta-delta axes ylabel.
11821194
1183-
11841195
contrast_bars : boolean, default True
11851196
Whether or not to display the contrast bars.
11861197
swarm_bars : boolean, default True

dabest/misc_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def get_params(effectsize_df, plot_kwargs):
116116
dabest_obj = effectsize_df.dabest_obj
117117
all_plot_groups = dabest_obj._all_plot_groups
118118
idx = dabest_obj.idx
119+
x1_level = dabest_obj.x1_level
120+
experiment_label = dabest_obj.experiment_label
119121

120122

121123
if effect_size not in ["mean_diff", "delta_g"] or not delta2:
@@ -170,7 +172,7 @@ def get_params(effectsize_df, plot_kwargs):
170172

171173
return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
172174
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,
173-
results, es_marker_size, halfviolin_alpha, ci_type)
175+
results, es_marker_size, halfviolin_alpha, ci_type, x1_level, experiment_label)
174176

175177
def get_kwargs(plot_kwargs, ytick_color):
176178
"""

dabest/plot_tools.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,21 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
15721572

15731573

15741574
def grid_key_WIP(is_paired, idx, all_plot_groups, gridkey_rows, rawdata_axes, contrast_axes,
1575-
plot_data, xvar, yvar, results, show_delta2, show_mini_meta, float_contrast, plot_kwargs,):
1575+
plot_data, xvar, yvar, results, show_delta2, show_mini_meta, float_contrast,
1576+
plot_kwargs, x1_level, experiment_label):
1577+
1578+
gridkey_delimiters=plot_kwargs["gridkey_delimiters"] # Auto parser for gridkey - implemented by SangyuXu
1579+
if gridkey_rows == "auto":
1580+
if experiment_label is not None:
1581+
gridkey_rows = list(np.concatenate([experiment_label, x1_level]))
1582+
else:
1583+
temp_groups = ";".join(all_plot_groups)
1584+
for delimiter in gridkey_delimiters:
1585+
temp_groups = temp_groups.replace(delimiter, ";")
1586+
temp_groups = [i.strip() for i in temp_groups.split(';')]
1587+
unique_groups = list(set(temp_groups))
1588+
rank = [sum([temp_groups.index(i) for i in temp_groups if(j in i)]) for j in unique_groups]
1589+
gridkey_rows = [x for _,x in sorted(zip(rank,unique_groups))]
15761590

15771591
gridkey_show_Ns=plot_kwargs["gridkey_show_Ns"]
15781592
gridkey_show_es=plot_kwargs["gridkey_show_es"]

dabest/plotter.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
113113
ytick_color = plt.rcParams["ytick.color"]
114114

115115
# Extract parameters and set kwargs
116-
(dabest_obj, plot_data, xvar, yvar, is_paired, effect_size,
117-
proportional, all_plot_groups, idx, show_delta2, show_mini_meta,
118-
float_contrast, show_pairs, effect_size_type, group_summaries,
119-
err_color, horizontal, results, es_marker_size, halfviolin_alpha, ci_type) = get_params(
116+
(dabest_obj, plot_data, xvar, yvar, is_paired,
117+
effect_size, proportional, all_plot_groups, idx, show_delta2,
118+
show_mini_meta, float_contrast, show_pairs, effect_size_type,
119+
group_summaries, err_color, horizontal, results,
120+
es_marker_size, halfviolin_alpha, ci_type, x1_level, experiment_label) = get_params(
120121
effectsize_df=effectsize_df,
121122
plot_kwargs=plot_kwargs,
122123
)
@@ -397,6 +398,8 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
397398
show_mini_meta=show_mini_meta,
398399
float_contrast=float_contrast,
399400
plot_kwargs=plot_kwargs,
401+
x1_level=x1_level,
402+
experiment_label=experiment_label,
400403
)
401404
skip_redraw_lines = True
402405

nbs/API/effsize_objects.ipynb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@
11601160
" gridkey_merge_pairs=False,\n",
11611161
" gridkey_show_Ns=True,\n",
11621162
" gridkey_show_es=True,\n",
1163+
" gridkey_delimiters=[';', '>', '_'],\n",
11631164
" swarmplot_kwargs=None,\n",
11641165
" barplot_kwargs=None,\n",
11651166
" violinplot_kwargs=None,\n",
@@ -1281,7 +1282,18 @@
12811282
" gridkey_rows : list, default None\n",
12821283
" Provide a list of row labels for the gridkey. The supplied idx is\n",
12831284
" checked against the row labels to determine whether the corresponding\n",
1284-
" cell should be populated or not.\n",
1285+
" cell should be populated or not. \n",
1286+
" This can also be set to \"auto\", which will attempt to auto populate the table.\n",
1287+
" gridkey_merge_pairs : boolean, default False\n",
1288+
" If True, the gridkey will merge the pairs of groups into a single\n",
1289+
" cell. This is useful for when the groups are paired.\n",
1290+
" gridkey_show_Ns : boolean, default True\n",
1291+
" If True, the gridkey will show the number of observations in each\n",
1292+
" group.\n",
1293+
" gridkey_show_es : boolean, default True\n",
1294+
" If True, the gridkey will show the effect size of each comparison.\n",
1295+
" gridkey_delimiters : list, default [';', '>', '_']\n",
1296+
" The delimiters used to separate the group names in the gridkey.\n",
12851297
" swarmplot_kwargs : dict, default None\n",
12861298
" Pass any keyword arguments accepted by the seaborn `swarmplot`\n",
12871299
" command here, as a dict. If None, the following keywords are\n",
@@ -1339,7 +1351,6 @@
13391351
" fontsize_delta2label : float, default 12\n",
13401352
" Font size for the delta-delta axes ylabel.\n",
13411353
" \n",
1342-
" \n",
13431354
" contrast_bars : boolean, default True\n",
13441355
" Whether or not to display the contrast bars.\n",
13451356
" swarm_bars : boolean, default True\n",

nbs/API/misc_tools.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@
169169
" dabest_obj = effectsize_df.dabest_obj\n",
170170
" all_plot_groups = dabest_obj._all_plot_groups\n",
171171
" idx = dabest_obj.idx\n",
172+
" x1_level = dabest_obj.x1_level\n",
173+
" experiment_label = dabest_obj.experiment_label\n",
172174
" \n",
173175
"\n",
174176
" if effect_size not in [\"mean_diff\", \"delta_g\"] or not delta2:\n",
@@ -223,7 +225,7 @@
223225
" \n",
224226
" return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx, \n",
225227
" show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,\n",
226-
" results, es_marker_size, halfviolin_alpha, ci_type)\n",
228+
" results, es_marker_size, halfviolin_alpha, ci_type, x1_level, experiment_label)\n",
227229
"\n",
228230
"def get_kwargs(plot_kwargs, ytick_color):\n",
229231
" \"\"\"\n",

nbs/API/plot_tools.ipynb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,21 @@
16221622
"\n",
16231623
"\n",
16241624
"def grid_key_WIP(is_paired, idx, all_plot_groups, gridkey_rows, rawdata_axes, contrast_axes,\n",
1625-
" plot_data, xvar, yvar, results, show_delta2, show_mini_meta, float_contrast, plot_kwargs,):\n",
1625+
" plot_data, xvar, yvar, results, show_delta2, show_mini_meta, float_contrast, \n",
1626+
" plot_kwargs, x1_level, experiment_label):\n",
1627+
" \n",
1628+
" gridkey_delimiters=plot_kwargs[\"gridkey_delimiters\"] # Auto parser for gridkey - implemented by SangyuXu\n",
1629+
" if gridkey_rows == \"auto\":\n",
1630+
" if experiment_label is not None:\n",
1631+
" gridkey_rows = list(np.concatenate([experiment_label, x1_level]))\n",
1632+
" else:\n",
1633+
" temp_groups = \";\".join(all_plot_groups)\n",
1634+
" for delimiter in gridkey_delimiters:\n",
1635+
" temp_groups = temp_groups.replace(delimiter, \";\")\n",
1636+
" temp_groups = [i.strip() for i in temp_groups.split(';')]\n",
1637+
" unique_groups = list(set(temp_groups))\n",
1638+
" rank = [sum([temp_groups.index(i) for i in temp_groups if(j in i)]) for j in unique_groups]\n",
1639+
" gridkey_rows = [x for _,x in sorted(zip(rank,unique_groups))]\n",
16261640
" \n",
16271641
" gridkey_show_Ns=plot_kwargs[\"gridkey_show_Ns\"]\n",
16281642
" gridkey_show_es=plot_kwargs[\"gridkey_show_es\"]\n",

nbs/API/plotter.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@
170170
" ytick_color = plt.rcParams[\"ytick.color\"]\n",
171171
"\n",
172172
" # Extract parameters and set kwargs\n",
173-
" (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, \n",
174-
" proportional, all_plot_groups, idx, show_delta2, show_mini_meta, \n",
175-
" float_contrast, show_pairs, effect_size_type, group_summaries, \n",
176-
" err_color, horizontal, results, es_marker_size, halfviolin_alpha, ci_type) = get_params(\n",
173+
" (dabest_obj, plot_data, xvar, yvar, is_paired, \n",
174+
" effect_size, proportional, all_plot_groups, idx, show_delta2, \n",
175+
" show_mini_meta, float_contrast, show_pairs, effect_size_type, \n",
176+
" group_summaries, err_color, horizontal, results, \n",
177+
" es_marker_size, halfviolin_alpha, ci_type, x1_level, experiment_label) = get_params(\n",
177178
" effectsize_df=effectsize_df, \n",
178179
" plot_kwargs=plot_kwargs,\n",
179180
" )\n",
@@ -454,6 +455,8 @@
454455
" show_mini_meta=show_mini_meta, \n",
455456
" float_contrast=float_contrast,\n",
456457
" plot_kwargs=plot_kwargs,\n",
458+
" x1_level=x1_level,\n",
459+
" experiment_label=experiment_label,\n",
457460
" )\n",
458461
" skip_redraw_lines = True\n",
459462
" \n",

0 commit comments

Comments
 (0)