Skip to content

Commit 5658cd0

Browse files
authored
Merge pull request #193 from ACCLAB/feat-horizontal-plots
Added Horizontal plots and various additional features, documentation, tutorial, tests, and improving code clarity
2 parents 3de867f + aa61ed2 commit 5658cd0

File tree

306 files changed

+8648
-2347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+8648
-2347
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# DABEST-Python
22

3+
34
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
45

56
[![minimal Python

dabest/_dabest_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# %% auto 0
66
__all__ = ['Dabest']
77

8-
# %% ../nbs/API/dabest_object.ipynb 4
8+
# %% ../nbs/API/dabest_object.ipynb 5
99
# Import standard data science libraries
1010
from numpy import array, repeat, random, issubdtype, number
1111
import numpy as np
1212
import pandas as pd
1313
from scipy.stats import norm
1414
from scipy.stats import randint
1515

16-
# %% ../nbs/API/dabest_object.ipynb 6
16+
# %% ../nbs/API/dabest_object.ipynb 7
1717
class Dabest(object):
1818

1919
"""

dabest/_effsize_objects.py

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,6 @@ def _perform_statistical_test(self):
358358
# References:
359359
# https://en.wikipedia.org/wiki/McNemar%27s_test
360360

361-
# df_temp = pd.DataFrame({"control": self.__control, "test": self.__test})
362-
# x1 = len(df_temp[(df_temp["control"] == 0) & (df_temp["test"] == 0)])
363-
# x2 = len(df_temp[(df_temp["control"] == 0) & (df_temp["test"] == 1)])
364-
# x3 = len(df_temp[(df_temp["control"] == 1) & (df_temp["test"] == 0)])
365-
# x4 = len(df_temp[(df_temp["control"] == 1) & (df_temp["test"] == 1)])
366-
# table = [[x1, x2], [x3, x4]]
367361
x1 = np.sum((self.__control == 0) & (self.__test == 0))
368362
x2 = np.sum((self.__control == 0) & (self.__test == 1))
369363
x3 = np.sum((self.__control == 1) & (self.__test == 0))
@@ -1146,21 +1140,16 @@ def plot(
11461140
show_delta2=True,
11471141
show_mini_meta=True,
11481142
group_summaries=None,
1149-
group_summaries_offset=0.1,
11501143
fig_size=None,
11511144
dpi=100,
11521145
ax=None,
1153-
gridkey_rows=None,
1154-
gridkey_merge_pairs=False,
1155-
gridkey_show_Ns=True,
1156-
gridkey_show_es=True,
11571146
swarmplot_kwargs=None,
11581147
barplot_kwargs=None,
11591148
violinplot_kwargs=None,
11601149
slopegraph_kwargs=None,
11611150
sankey_kwargs=None,
11621151
reflines_kwargs=None,
1163-
group_summary_kwargs=None,
1152+
group_summaries_kwargs=None,
11641153
legend_kwargs=None,
11651154
title=None,
11661155
fontsize_title=16,
@@ -1169,7 +1158,7 @@ def plot(
11691158
fontsize_contrastxlabel=12,
11701159
fontsize_contrastylabel=12,
11711160
fontsize_delta2label=12,
1172-
#### Contrast bars and delta text and delta dots WIP ####
1161+
#### Contrast bars, Swarm bars, delta text, and delta dots WIP ####
11731162
contrast_bars=True,
11741163
swarm_bars=True,
11751164
contrast_bars_kwargs=None,
@@ -1180,7 +1169,30 @@ def plot(
11801169
delta_text_kwargs=None,
11811170
delta_dot=True,
11821171
delta_dot_kwargs=None,
1183-
show_baseline_ec=False,
1172+
1173+
# Horizontal Plots
1174+
horizontal=False,
1175+
horizontal_table_kwargs=None,
1176+
1177+
# Gridkey
1178+
gridkey_rows=None,
1179+
gridkey_merge_pairs=False,
1180+
gridkey_show_Ns=True,
1181+
gridkey_show_es=True,
1182+
gridkey_delimiters=[';', '>', '_'],
1183+
gridkey_kwargs=None,
1184+
1185+
es_marker_kwargs=None,
1186+
es_errorbar_kwargs=None,
1187+
1188+
prop_sample_counts=False,
1189+
prop_sample_counts_kwargs=None,
1190+
1191+
es_paired_lines=True,
1192+
es_paired_lines_kwargs=None,
1193+
1194+
# Basline EffectSize Curve
1195+
show_baseline_ec=False,
11841196
):
11851197
"""
11861198
Creates an estimation plot for the effect size of interest.
@@ -1259,24 +1271,20 @@ def plot(
12591271
notched line beside each group. If 'median_quantiles', then the
12601272
median and 25th and 75th percentiles of each group is plotted
12611273
instead. If 'None', the summaries are not shown.
1262-
group_summaries_offset : float, default 0.1
1263-
If group summaries are displayed, they will be offset from the raw
1264-
data swarmplot groups by this value.
12651274
fig_size : tuple, default None
12661275
The desired dimensions of the figure as a (length, width) tuple.
12671276
dpi : int, default 100
12681277
The dots per inch of the resulting figure.
12691278
ax : matplotlib.Axes, default None
12701279
Provide an existing Axes for the plots to be created. If no Axes is
12711280
specified, a new matplotlib Figure will be created.
1272-
gridkey_rows : list, default None
1273-
Provide a list of row labels for the gridkey. The supplied idx is
1274-
checked against the row labels to determine whether the corresponding
1275-
cell should be populated or not.
12761281
swarmplot_kwargs : dict, default None
12771282
Pass any keyword arguments accepted by the seaborn `swarmplot`
12781283
command here, as a dict. If None, the following keywords are
12791284
passed to sns.swarmplot : {'size':`raw_marker_size`}.
1285+
barplot_kwargs : dict, default None
1286+
By default, the keyword arguments passed are:
1287+
{"estimator": np.mean, "errorbar": plot_kwargs["ci"]}
12801288
violinplot_kwargs : dict, default None
12811289
Pass any keyword arguments accepted by the matplotlib `
12821290
pyplot.violinplot` command here, as a dict. If None, the following
@@ -1287,7 +1295,7 @@ def plot(
12871295
of observations when `show_pairs=True`. Pass any keyword arguments
12881296
accepted by matplotlib `plot()` function here, as a dict.
12891297
If None, the following keywords are
1290-
passed to plot() : {'linewidth':1, 'alpha':0.5}.
1298+
passed to plot() : {'linewidth':1, 'alpha':0.5, 'jitter':0, 'jitter_seed':9876543210}.
12911299
sankey_kwargs: dict, default None
12921300
Whis will change the appearance of the sankey diagram used to depict
12931301
paired proportional data when `show_pairs=True` and `proportional=True`.
@@ -1300,12 +1308,13 @@ def plot(
13001308
command here, as a dict. If None, the following keywords are
13011309
passed to Axes.hlines : {'linestyle':'solid', 'linewidth':0.75,
13021310
'zorder':2, 'color' : default y-tick color}.
1303-
group_summary_kwargs : dict, default None
1311+
group_summaries_kwargs : dict, default None
13041312
Pass any keyword arguments accepted by the matplotlib.lines.Line2D
13051313
command here, as a dict. This will change the appearance of the
13061314
vertical summary lines for each group, if `group_summaries` is not
13071315
'None'. If None, the following keywords are passed to
1308-
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3}.
1316+
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3,
1317+
'gap_width_percent':1.5, 'offset':0.1, 'color':None}.
13091318
legend_kwargs : dict, default None
13101319
Pass any keyword arguments accepted by the matplotlib Axes
13111320
`legend` command here, as a dict. If None, the following keywords
@@ -1330,39 +1339,73 @@ def plot(
13301339
fontsize_delta2label : float, default 12
13311340
Font size for the delta-delta axes ylabel.
13321341
1333-
13341342
contrast_bars : boolean, default True
13351343
Whether or not to display the contrast bars.
13361344
swarm_bars : boolean, default True
13371345
Whether or not to display the swarm bars.
13381346
contrast_bars_kwargs : dict, default None
13391347
Pass relevant keyword arguments to the contrast bars. Pass any keyword arguments accepted by
13401348
matplotlib.patches.Rectangle here, as a string. If None, the following keywords are passed:
1341-
{"color": None, "alpha": 0.3}
1349+
{"color": None, "zorder":-3}
13421350
swarm_bars_kwargs : dict, default None
13431351
Pass relevant keyword arguments to the swarm bars. Pass any keyword arguments accepted by
13441352
matplotlib.patches.Rectangle here, as a string. If None, the following keywords are passed:
1345-
{"color": None, "alpha": 0.3}
1353+
{"color": None, "zorder":-3}
13461354
13471355
summary_bars : list, default None
13481356
Pass a list of indices of the contrast objects to have summary bars displayed on the plot.
13491357
For example, [0,1] will show summary bars for the first two contrast objects.
13501358
summary_bars_kwargs: dict, default None
1351-
If None, the following keywords are passed: {"color": None, "alpha": 0.15}
1359+
If None, the following keywords are passed: {"span_ax": False, "color": None, "alpha": 0.15, "zorder":-3}
13521360
delta_text : boolean, default True
13531361
Whether or not to display the text deltas.
13541362
delta_text_kwargs : dict, default None
13551363
Pass relevant keyword arguments to the delta text. Pass any keyword arguments accepted by
13561364
matplotlib.text.Text here, as a string. If None, the following keywords are passed:
13571365
{"color": None, "alpha": 1, "fontsize": 10, "ha": 'center', "va": 'center', "rotation": 0,
1358-
"x_location": 'right', "x_coordinates": None, "y_coordinates": None}
1359-
Use "x_coordinates" and "y_coordinates" if you would like to specify the text locations manually.
1366+
"x_location": 'right', "x_coordinates": None, "y_coordinates": None, "offset": 0}
1367+
Use "x_coordinates" and "y_coordinates" if you would like to specify the text locations manually.
1368+
Use "x_adjust" to adjust the x location of all the texts (positive moves right, negative left).
13601369
delta_dot : boolean, default True
13611370
Whether or not to display the delta dots on paired or repeated measure plots.
13621371
delta_dot_kwargs : dict, default None
13631372
Pass relevant keyword arguments. If None, the following keywords are passed:
1364-
{"marker": "^", "alpha": 0.5, "zorder": 2, "size": 3, "side": "right"}
1365-
show_baseline_ec : boolean, default False
1373+
{"color": 'k', "marker": "^", "alpha": 0.5, "zorder": -1, "size": 3, "side": "right"}
1374+
1375+
horizontal_table_kwargs : dict, default None
1376+
{'show: True, 'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black',
1377+
'text_units' : None, 'control_marker' : '-', 'fontsize_label': 12, 'label': 'Δ'}
1378+
1379+
gridkey_rows : list, default None
1380+
cell should be populated or not.
1381+
Pass relevant keyword arguments to the gridkey. If None, the following keywords are passed:
1382+
{ 'show_es' : True, # If True, the gridkey will show the effect size of each comparison.
1383+
'show_Ns' :True, # If True, the gridkey will show the number of observations in eachgroup.
1384+
'merge_pairs' : False, # If True, the gridkey will merge the pairs of groups into a single cell. This is useful for when the groups are paired.
1385+
'delimiters': [';', '>', '_'], # Delimiters to split the group names.
1386+
'marker': "\u25CF", # Marker for the gridkey dots.
1387+
}
1388+
1389+
es_marker_kwargs: dict, default None
1390+
Pass relevant keyword arguments to the effectsize marker plotting. If none, the following keywords are passed:
1391+
{'marker': 'o', 'size': plot_kwargs['es_marker_size'], 'color': 'black', 'alpha': 1, 'zorder': 1}
1392+
es_errorbar_kwargs: dict, default None
1393+
Pass relevant keyword arguments to the effectsize errorbar plotting. If none, the following keywords are passed:
1394+
{'color': 'black', 'lw': 2, 'linestyle': '-', 'alpha': 1,'zorder': 1,}
1395+
1396+
prop_sample_counts: bool, default False
1397+
Show the sample counts for each group in proportional plots
1398+
prop_sample_counts_kwargs: dict, default None
1399+
Pass relevant keyword arguments. If None, the following keywords are passed:
1400+
{'color': 'k', 'zorder': 5, 'ha': 'center', 'va': 'center'},
1401+
1402+
es_paired_lines: bool, default True
1403+
Whether or not to add lines to connect the effect size curves in paired plots.
1404+
es_paired_lines_kwargs: dict, default None
1405+
Pass relevant plot keyword arguments. If None, the following keywords are passed:
1406+
{"linestyle": "-", "linewidth": 2, "zorder": -2, "color": 'dimgray', "alpha": 1}
1407+
1408+
show_baseline_ec : boolean, default False
13661409
Whether or not to display the baseline error curve. The baseline error curve
13671410
represents the distribution of the effect size when comparing the control
13681411
group to itself, providing a reference for the inherent variability or noise
@@ -1402,7 +1445,6 @@ def plot(
14021445
del all_kwargs["self"]
14031446

14041447
out = effectsize_df_plotter(self, **all_kwargs)
1405-
14061448
return out
14071449

14081450
@property

dabest/_modidx.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@
8181
'dabest/misc_tools.py'),
8282
'dabest.misc_tools.Gardner_Altman_Plot_Aesthetic_Adjustments': ( 'API/misc_tools.html#gardner_altman_plot_aesthetic_adjustments',
8383
'dabest/misc_tools.py'),
84-
'dabest.misc_tools.General_Plot_Aesthetic_Adjustments': ( 'API/misc_tools.html#general_plot_aesthetic_adjustments',
85-
'dabest/misc_tools.py'),
84+
'dabest.misc_tools.Redraw_Spines': ('API/misc_tools.html#redraw_spines', 'dabest/misc_tools.py'),
8685
'dabest.misc_tools.add_counts_to_ticks': ( 'API/misc_tools.html#add_counts_to_ticks',
8786
'dabest/misc_tools.py'),
8887
'dabest.misc_tools.extract_contrast_plotting_ticks': ( 'API/misc_tools.html#extract_contrast_plotting_ticks',
8988
'dabest/misc_tools.py'),
89+
'dabest.misc_tools.extract_group_summaries': ( 'API/misc_tools.html#extract_group_summaries',
90+
'dabest/misc_tools.py'),
9091
'dabest.misc_tools.get_color_palette': ('API/misc_tools.html#get_color_palette', 'dabest/misc_tools.py'),
9192
'dabest.misc_tools.get_kwargs': ('API/misc_tools.html#get_kwargs', 'dabest/misc_tools.py'),
9293
'dabest.misc_tools.get_params': ('API/misc_tools.html#get_params', 'dabest/misc_tools.py'),
@@ -115,6 +116,8 @@
115116
'dabest/plot_tools.py'),
116117
'dabest.plot_tools.SwarmPlot._swarm': ('API/plot_tools.html#swarmplot._swarm', 'dabest/plot_tools.py'),
117118
'dabest.plot_tools.SwarmPlot.plot': ('API/plot_tools.html#swarmplot.plot', 'dabest/plot_tools.py'),
119+
'dabest.plot_tools.add_counts_to_prop_plots': ( 'API/plot_tools.html#add_counts_to_prop_plots',
120+
'dabest/plot_tools.py'),
118121
'dabest.plot_tools.barplotter': ('API/plot_tools.html#barplotter', 'dabest/plot_tools.py'),
119122
'dabest.plot_tools.check_data_matches_labels': ( 'API/plot_tools.html#check_data_matches_labels',
120123
'dabest/plot_tools.py'),
@@ -126,7 +129,7 @@
126129
'dabest/plot_tools.py'),
127130
'dabest.plot_tools.error_bar': ('API/plot_tools.html#error_bar', 'dabest/plot_tools.py'),
128131
'dabest.plot_tools.get_swarm_spans': ('API/plot_tools.html#get_swarm_spans', 'dabest/plot_tools.py'),
129-
'dabest.plot_tools.grid_key_WIP': ('API/plot_tools.html#grid_key_wip', 'dabest/plot_tools.py'),
132+
'dabest.plot_tools.gridkey_plotter': ('API/plot_tools.html#gridkey_plotter', 'dabest/plot_tools.py'),
130133
'dabest.plot_tools.halfviolin': ('API/plot_tools.html#halfviolin', 'dabest/plot_tools.py'),
131134
'dabest.plot_tools.normalize_dict': ('API/plot_tools.html#normalize_dict', 'dabest/plot_tools.py'),
132135
'dabest.plot_tools.plot_minimeta_or_deltadelta_violins': ( 'API/plot_tools.html#plot_minimeta_or_deltadelta_violins',
@@ -140,5 +143,7 @@
140143
'dabest.plot_tools.swarm_bars_plotter': ( 'API/plot_tools.html#swarm_bars_plotter',
141144
'dabest/plot_tools.py'),
142145
'dabest.plot_tools.swarmplot': ('API/plot_tools.html#swarmplot', 'dabest/plot_tools.py'),
146+
'dabest.plot_tools.table_for_horizontal_plots': ( 'API/plot_tools.html#table_for_horizontal_plots',
147+
'dabest/plot_tools.py'),
143148
'dabest.plot_tools.width_determine': ('API/plot_tools.html#width_determine', 'dabest/plot_tools.py')},
144149
'dabest.plotter': {'dabest.plotter.effectsize_df_plotter': ('API/plotter.html#effectsize_df_plotter', 'dabest/plotter.py')}}}

0 commit comments

Comments
 (0)