Skip to content

Commit fa60e76

Browse files
committed
Added tutorial for group_summaries (gapped lines) and added more kwargs and clarified naming conventions.
1 parent 02140b1 commit fa60e76

34 files changed

+408
-143
lines changed

dabest/_effsize_objects.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ def plot(
993993
show_delta2=True,
994994
show_mini_meta=True,
995995
group_summaries=None,
996-
group_summaries_offset=0.1,
997996
fig_size=None,
998997
dpi=100,
999998
ax=None,
@@ -1003,7 +1002,7 @@ def plot(
10031002
slopegraph_kwargs=None,
10041003
sankey_kwargs=None,
10051004
reflines_kwargs=None,
1006-
group_summary_kwargs=None,
1005+
group_summaries_kwargs=None,
10071006
legend_kwargs=None,
10081007
title=None,
10091008
fontsize_title=16,
@@ -1035,6 +1034,9 @@ def plot(
10351034
gridkey_show_es=True,
10361035
gridkey_delimiters=[';', '>', '_'],
10371036
gridkey_kwargs=None,
1037+
1038+
es_marker_kwargs=None,
1039+
es_errorbar_kwargs=None,
10381040
):
10391041
"""
10401042
Creates an estimation plot for the effect size of interest.
@@ -1113,9 +1115,6 @@ def plot(
11131115
notched line beside each group. If 'median_quantiles', then the
11141116
median and 25th and 75th percentiles of each group is plotted
11151117
instead. If 'None', the summaries are not shown.
1116-
group_summaries_offset : float, default 0.1
1117-
If group summaries are displayed, they will be offset from the raw
1118-
data swarmplot groups by this value.
11191118
fig_size : tuple, default None
11201119
The desired dimensions of the figure as a (length, width) tuple.
11211120
dpi : int, default 100
@@ -1150,12 +1149,13 @@ def plot(
11501149
command here, as a dict. If None, the following keywords are
11511150
passed to Axes.hlines : {'linestyle':'solid', 'linewidth':0.75,
11521151
'zorder':2, 'color' : default y-tick color}.
1153-
group_summary_kwargs : dict, default None
1152+
group_summaries_kwargs : dict, default None
11541153
Pass any keyword arguments accepted by the matplotlib.lines.Line2D
11551154
command here, as a dict. This will change the appearance of the
11561155
vertical summary lines for each group, if `group_summaries` is not
11571156
'None'. If None, the following keywords are passed to
1158-
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3, 'gap_width_percent':1.5}.
1157+
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3,
1158+
'gap_width_percent':1.5, 'offset':0.1, 'color':None}.
11591159
legend_kwargs : dict, default None
11601160
Pass any keyword arguments accepted by the matplotlib Axes
11611161
`legend` command here, as a dict. If None, the following keywords
@@ -1234,6 +1234,12 @@ def plot(
12341234
'marker': "\u25CF", # Marker for the gridkey dots.
12351235
}
12361236
1237+
es_marker_kwargs: dict, default None
1238+
Pass relevant keyword arguments to the effectsize marker plotting. If none, the following keywords are passed:
1239+
{'marker': 'o', 'size': plot_kwargs['es_marker_size'], 'color': 'black', 'alpha': 1, 'zorder': 1}
1240+
es_errorbar_kwargs: dict, default None
1241+
Pass relevant keyword arguments to the effectsize errorbar plotting. If none, the following keywords are passed:
1242+
{'color': 'black', 'lw': 2, 'linestyle': '-', 'alpha': 1,'zorder': 1,}
12371243
12381244
Returns
12391245
-------

dabest/misc_tools.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,12 @@ def get_params(effectsize_df, plot_kwargs):
166166
float_contrast = False
167167

168168
# Contrast Axes kwargs
169-
es_marker_size = plot_kwargs["es_marker_size"]
170169
halfviolin_alpha = plot_kwargs["halfviolin_alpha"]
171170
ci_type = plot_kwargs["ci_type"]
172171

173172
return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
174173
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,
175-
results, es_marker_size, halfviolin_alpha, ci_type, x1_level, experiment_label)
174+
results, halfviolin_alpha, ci_type, x1_level, experiment_label)
176175

177176
def get_kwargs(plot_kwargs, ytick_color):
178177
"""
@@ -233,6 +232,7 @@ def get_kwargs(plot_kwargs, ytick_color):
233232
"vert": True,
234233
"showextrema": False,
235234
"showmedians": False,
235+
236236
}
237237
if plot_kwargs["violinplot_kwargs"] is None:
238238
violinplot_kwargs = default_violinplot_kwargs
@@ -292,17 +292,19 @@ def get_kwargs(plot_kwargs, ytick_color):
292292
"group_summaries must be one of" " these: {}.".format(gs_default)
293293
)
294294

295-
default_group_summary_kwargs = {
295+
default_group_summaries_kwargs = {
296296
"zorder": 3,
297297
"lw": 2,
298298
"alpha": 1,
299299
'gap_width_percent': 1.5,
300+
'offset': 0.1,
301+
'color': None
300302
}
301-
if plot_kwargs["group_summary_kwargs"] is None:
302-
group_summary_kwargs = default_group_summary_kwargs
303+
if plot_kwargs["group_summaries_kwargs"] is None:
304+
group_summaries_kwargs = default_group_summaries_kwargs
303305
else:
304-
group_summary_kwargs = merge_two_dicts(
305-
default_group_summary_kwargs, plot_kwargs["group_summary_kwargs"]
306+
group_summaries_kwargs = merge_two_dicts(
307+
default_group_summaries_kwargs, plot_kwargs["group_summaries_kwargs"]
306308
)
307309

308310
# Redraw axes kwargs.
@@ -404,10 +406,37 @@ def get_kwargs(plot_kwargs, ytick_color):
404406
else:
405407
gridkey_kwargs = merge_two_dicts(default_gridkey_kwargs, plot_kwargs["gridkey_kwargs"])
406408

409+
# Effect size marker kwargs
410+
default_es_marker_kwargs = {
411+
'marker': 'o',
412+
'markersize': plot_kwargs['es_marker_size'],
413+
'color': ytick_color,
414+
'alpha': 1,
415+
'zorder': 1,
416+
}
417+
if plot_kwargs['es_marker_kwargs'] is None:
418+
es_marker_kwargs = default_es_marker_kwargs
419+
else:
420+
es_marker_kwargs = merge_two_dicts(default_es_marker_kwargs, plot_kwargs['es_marker_kwargs'])
421+
422+
# Effect size error bar kwargs
423+
default_es_errorbar_kwargs = {
424+
'color': ytick_color,
425+
'lw': 2,
426+
'linestyle': '-',
427+
'alpha': 1,
428+
'zorder': 1,
429+
}
430+
if plot_kwargs['es_errorbar_kwargs'] is None:
431+
es_errorbar_kwargs = default_es_errorbar_kwargs
432+
else:
433+
es_errorbar_kwargs = merge_two_dicts(default_es_errorbar_kwargs, plot_kwargs['es_errorbar_kwargs'])
434+
407435
# Return the kwargs.
408436
return (swarmplot_kwargs, barplot_kwargs, sankey_kwargs, violinplot_kwargs, slopegraph_kwargs,
409-
reflines_kwargs, legend_kwargs, group_summary_kwargs, redraw_axes_kwargs, delta_dot_kwargs,
410-
delta_text_kwargs, summary_bars_kwargs, swarm_bars_kwargs, contrast_bars_kwargs, table_kwargs, gridkey_kwargs)
437+
reflines_kwargs, legend_kwargs, group_summaries_kwargs, redraw_axes_kwargs, delta_dot_kwargs,
438+
delta_text_kwargs, summary_bars_kwargs, swarm_bars_kwargs, contrast_bars_kwargs, table_kwargs, gridkey_kwargs,
439+
es_marker_kwargs, es_errorbar_kwargs)
411440

412441

413442
def get_color_palette(plot_kwargs, plot_data, xvar, show_pairs, idx, all_plot_groups):
@@ -1539,7 +1568,7 @@ def Redraw_Spines(rawdata_axes, contrast_axes, redraw_axes_kwargs, float_contras
15391568

15401569
def extract_group_summaries(proportional, err_color, rawdata_axes, asymmetric_side, horizontal,
15411570
bootstraps_color_by_group, plot_palette_raw, all_plot_groups,
1542-
n_groups, color_col, ytick_color, plot_kwargs):
1571+
n_groups, color_col, ytick_color, group_summaries_kwargs):
15431572

15441573
from .plot_tools import get_swarm_spans
15451574

@@ -1582,7 +1611,11 @@ def extract_group_summaries(proportional, err_color, rawdata_axes, asymmetric_si
15821611
xspans = xspans[:len(all_plot_groups)]
15831612

15841613
group_summaries_method = "gapped_lines"
1585-
group_summaries_offset = xspans + np.array(plot_kwargs["group_summaries_offset"])
1614+
group_summaries_offset = xspans + np.array(group_summaries_kwargs["offset"])
15861615
group_summaries_line_color = line_colors
15871616

1617+
if group_summaries_kwargs['color'] is not None:
1618+
group_summaries_line_color = group_summaries_kwargs.pop("color")
1619+
group_summaries_kwargs.pop("offset")
1620+
15881621
return group_summaries_method, group_summaries_offset, group_summaries_line_color

dabest/plot_tools.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ def slopegraph_plotter(dabest_obj, plot_data, xvar, yvar, color_col, plot_palett
13701370

13711371
def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type, rawdata_axes,
13721372
contrast_axes, violinplot_kwargs, halfviolin_alpha, ytick_color,
1373-
es_marker_size, group_summary_kwargs, contrast_xtick_labels, effect_size,
1374-
show_delta2, plot_kwargs, horizontal):
1373+
contrast_xtick_labels, effect_size, show_delta2, plot_kwargs,
1374+
horizontal, es_marker_kwargs, es_errorbar_kwargs):
13751375
"""
13761376
Add mini meta-analysis or delta-delta violin plots to the contrast plot.
13771377
@@ -1395,8 +1395,6 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
13951395
Color of the yticks.
13961396
es_marker_size : int
13971397
Size of the effect size marker.
1398-
group_summary_kwargs : dict
1399-
Keyword arguments for the group summary.
14001398
contrast_xtick_labels : list
14011399
List of xtick labels for the contrast plot.
14021400
effect_size : str
@@ -1407,7 +1405,13 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
14071405
Keyword arguments for the plot.
14081406
horizontal : bool
14091407
If the plot is horizontal.
1408+
es_marker_kwargs: dict
1409+
Keyword arguments for the effectsize marker.
1410+
es_errorbar_kwargs: dict
1411+
Keyword arguments for the effectsize errorbar.
14101412
"""
1413+
1414+
# Plot the curve
14111415
if show_mini_meta:
14121416
mini_meta_delta = effectsize_df.mini_meta_delta
14131417
data = mini_meta_delta.bootstraps_weighted_delta
@@ -1449,17 +1453,15 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
14491453
contrast_axes.plot(
14501454
effsize_x,
14511455
effsize_y,
1452-
marker="o",
1453-
color=ytick_color,
1454-
markersize=es_marker_size,
1456+
# color=ytick_color,
1457+
**es_marker_kwargs
14551458
)
14561459
# Plot the confidence interval.
14571460
contrast_axes.plot(
14581461
ci_x,
14591462
ci_y,
1460-
linestyle="-",
1461-
color=ytick_color,
1462-
linewidth=group_summary_kwargs["lw"],
1463+
# color=ytick_color,
1464+
**es_errorbar_kwargs
14631465
)
14641466

14651467
if horizontal:
@@ -1505,8 +1507,8 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
15051507

15061508

15071509
def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, violinplot_kwargs, halfviolin_alpha,
1508-
ytick_color, es_marker_size, group_summary_kwargs, bootstraps_color_by_group, plot_palette_contrast,
1509-
horizontal):
1510+
ytick_color, bootstraps_color_by_group, plot_palette_contrast,
1511+
horizontal, es_marker_kwargs, es_errorbar_kwargs):
15101512
"""
15111513
Add effect size curves to the contrast plot.
15121514
@@ -1528,16 +1530,19 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
15281530
Color of the yticks.
15291531
es_marker_size : int
15301532
Size of the effect size marker.
1531-
group_summary_kwargs : dict
1532-
Keyword arguments for the group summary.
15331533
bootstraps_color_by_group : bool
15341534
Whether to color the bootstraps by group.
15351535
plot_palette_contrast : dict
15361536
Dictionary of colors used in the contrast plot.
15371537
horizontal : bool
15381538
If the plot is horizontal.
1539+
es_marker_kwargs: dict
1540+
Keyword arguments for the effectsize marker.
1541+
es_errorbar_kwargs: dict
1542+
Keyword arguments for the effectsize errorbar.
15391543
"""
15401544

1545+
# Plot the curves
15411546
contrast_xtick_labels = []
15421547
for j, tick in enumerate(ticks_to_plot):
15431548
current_group = results.test[j]
@@ -1582,18 +1587,16 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
15821587
contrast_axes.plot(
15831588
effsize_x,
15841589
effsize_y,
1585-
marker="o",
1586-
color=ytick_color,
1587-
markersize=es_marker_size,
1590+
# color=ytick_color,
1591+
**es_marker_kwargs
15881592
)
15891593

15901594
# Plot the confidence interval.
15911595
contrast_axes.plot(
15921596
ci_x,
15931597
ci_y,
1594-
linestyle="-",
1595-
color=ytick_color,
1596-
linewidth=group_summary_kwargs["lw"],
1598+
# color=ytick_color,
1599+
**es_errorbar_kwargs
15971600
)
15981601

15991602
contrast_xtick_labels.append(

0 commit comments

Comments
 (0)