Skip to content

Commit 71d0d93

Browse files
committed
More documentation
1 parent d254128 commit 71d0d93

9 files changed

Lines changed: 749 additions & 181 deletions

File tree

dabest/_dabest_object.py

Lines changed: 3 additions & 3 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
"""
@@ -122,7 +122,7 @@ def __init__(
122122
self.__idx = (idx,)
123123

124124
elif all([isinstance(i, (tuple, list)) for i in idx]):
125-
all_plot_groups = pd.unique([tt for t in idx for tt in t]).tolist()
125+
all_plot_groups = pd.Series([tt for t in idx for tt in t]).unique().tolist()
126126

127127
actual_groups_given = sum([len(i) for i in idx])
128128

dabest/misc_tools.py

Lines changed: 168 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import seaborn as sns
1818
import matplotlib.pyplot as plt
1919
import matplotlib
20+
import matplotlib.axes as axes
2021

2122
# %% ../nbs/API/misc_tools.ipynb 5
2223
def merge_two_dicts(
@@ -93,7 +94,10 @@ def get_unique_categories(names):
9394
# For dict_keys and other iterables
9495
return np.unique(list(names))
9596

96-
def get_params(effectsize_df: object, plot_kwargs: dict):
97+
def get_params(
98+
effectsize_df: object,
99+
plot_kwargs: dict
100+
):
97101
"""
98102
Extracts parameters from the `effectsize_df` and `plot_kwargs` objects for use in the plotter function.
99103
@@ -172,15 +176,18 @@ def get_params(effectsize_df: object, plot_kwargs: dict):
172176
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color, horizontal,
173177
results, halfviolin_alpha, ci_type, x1_level, experiment_label)
174178

175-
def get_kwargs(plot_kwargs, ytick_color):
179+
def get_kwargs(
180+
plot_kwargs: dict,
181+
ytick_color
182+
):
176183
"""
177184
Extracts the kwargs from the `plot_kwargs` object for use in the plotter function.
178185
179186
Parameters
180187
----------
181188
plot_kwargs : dict
182189
Kwargs passed to the plot function.
183-
ytick_color : str
190+
ytick_color : str or color list
184191
Color of the yticks.
185192
"""
186193
from .misc_tools import merge_two_dicts
@@ -468,7 +475,14 @@ def get_kwargs(plot_kwargs, ytick_color):
468475
es_marker_kwargs, es_errorbar_kwargs, prop_sample_counts_kwargs, es_paired_lines_kwargs)
469476

470477

471-
def get_color_palette(plot_kwargs, plot_data, xvar, show_pairs, idx, all_plot_groups):
478+
def get_color_palette(
479+
plot_kwargs: dict,
480+
plot_data: pd.DataFrame,
481+
xvar: str,
482+
show_pairs: bool,
483+
idx: list,
484+
all_plot_groups: list
485+
):
472486
"""
473487
Create the color palette to be used in the plotter function.
474488
@@ -600,8 +614,20 @@ def get_color_palette(plot_kwargs, plot_data, xvar, show_pairs, idx, all_plot_gr
600614
return (color_col, bootstraps_color_by_group, n_groups, filled, plot_palette_raw, bar_color,
601615
plot_palette_bar, plot_palette_contrast, plot_palette_sankey)
602616

603-
def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_paired, show_pairs, proportional,
604-
float_contrast, effect_size_type, yvar, horizontal, show_table):
617+
def initialize_fig(
618+
plot_kwargs: dict,
619+
dabest_obj: object,
620+
show_delta2: bool,
621+
show_mini_meta: bool,
622+
is_paired: bool,
623+
show_pairs: bool,
624+
proportional: bool,
625+
float_contrast: bool,
626+
effect_size_type: str,
627+
yvar: str,
628+
horizontal: bool,
629+
show_table: bool
630+
):
605631
"""
606632
Initialize the figure and axes for the plotter function.
607633
@@ -868,7 +894,12 @@ def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_pair
868894

869895
return fig, rawdata_axes, contrast_axes, table_axes
870896

871-
def get_plot_groups(is_paired, idx, proportional, all_plot_groups):
897+
def get_plot_groups(
898+
is_paired: bool,
899+
idx: list,
900+
proportional: bool,
901+
all_plot_groups: list
902+
):
872903
"""
873904
Extract the plot groups from the `idx` object for use in the plotter function.
874905
@@ -904,7 +935,15 @@ def get_plot_groups(is_paired, idx, proportional, all_plot_groups):
904935
return temp_idx, temp_all_plot_groups
905936

906937

907-
def add_counts_to_ticks(plot_data, xvar, yvar, rawdata_axes, plot_kwargs, flow, horizontal):
938+
def add_counts_to_ticks(
939+
plot_data: pd.DataFrame,
940+
xvar: str,
941+
yvar: str,
942+
rawdata_axes: axes.Axes,
943+
plot_kwargs: dict,
944+
flow: bool,
945+
horizontal: bool
946+
):
908947
"""
909948
910949
Add the counts to the raw data axes labels.
@@ -971,7 +1010,14 @@ def lookup_value(text):
9711010
# Ensure ticks are at the correct locations
9721011
set_major_loc_method(plt.FixedLocator(get_ticks()))
9731012

974-
def extract_contrast_plotting_ticks(is_paired, show_pairs, two_col_sankey, plot_groups, idx, sankey_control_group):
1013+
def extract_contrast_plotting_ticks(
1014+
is_paired: bool,
1015+
show_pairs: bool,
1016+
two_col_sankey: bool,
1017+
plot_groups: list,
1018+
idx: list,
1019+
sankey_control_group: list
1020+
):
9751021
"""
9761022
Extract the contrast plotting ticks from the `idx` object for use in the plotter function.
9771023
@@ -988,7 +1034,7 @@ def extract_contrast_plotting_ticks(is_paired, show_pairs, two_col_sankey, plot_
9881034
idx : list
9891035
A list of tuples containing the group names.
9901036
sankey_control_group : list
991-
TBC.
1037+
A list of the control group names.
9921038
"""
9931039
# Take note of where the `control` groups are.
9941040
ticks_to_skip_contrast = None
@@ -1030,8 +1076,18 @@ def extract_contrast_plotting_ticks(is_paired, show_pairs, two_col_sankey, plot_
10301076

10311077
return ticks_to_skip, ticks_to_plot, ticks_to_skip_contrast, ticks_to_start_twocol_sankey
10321078

1033-
def set_xaxis_ticks_and_lims(show_delta2, show_mini_meta, rawdata_axes, contrast_axes, show_pairs, float_contrast,
1034-
ticks_to_skip, contrast_xtick_labels, plot_kwargs, proportional, horizontal):
1079+
def set_xaxis_ticks_and_lims(
1080+
show_delta2: bool,
1081+
show_mini_meta: bool,
1082+
rawdata_axes: axes.Axes,
1083+
contrast_axes: axes.Axes,
1084+
show_pairs: bool,
1085+
float_contrast: bool,
1086+
ticks_to_skip: list,
1087+
contrast_xtick_labels: list,
1088+
plot_kwargs: dict,
1089+
proportional: bool,
1090+
horizontal: bool):
10351091
"""
10361092
Set the x-axis/yaxis ticks and limits for the plotter function.
10371093
@@ -1125,7 +1181,18 @@ def set_xaxis_ticks_and_lims(show_delta2, show_mini_meta, rawdata_axes, contrast
11251181
)
11261182

11271183

1128-
def show_legend(legend_labels, legend_handles, rawdata_axes, contrast_axes, table_axes, float_contrast, show_pairs, horizontal, legend_kwargs, table_kwargs):
1184+
def show_legend(
1185+
legend_labels: list,
1186+
legend_handles: list,
1187+
rawdata_axes: axes.Axes,
1188+
contrast_axes: axes.Axes,
1189+
table_axes: axes.Axes,
1190+
float_contrast: bool,
1191+
show_pairs: bool,
1192+
horizontal: bool,
1193+
legend_kwargs: dict,
1194+
table_kwargs: dict
1195+
):
11291196
"""
11301197
Show the legend for the plotter function.
11311198
@@ -1191,9 +1258,22 @@ def show_legend(legend_labels, legend_handles, rawdata_axes, contrast_axes, tabl
11911258
for line in leg.get_lines():
11921259
line.set_linewidth(3.0)
11931260

1194-
def Gardner_Altman_Plot_Aesthetic_Adjustments(effect_size_type, plot_data, xvar, yvar, current_control, current_group,
1195-
rawdata_axes, contrast_axes, results, current_effsize, is_paired, one_sankey,
1196-
reflines_kwargs, redraw_axes_kwargs):
1261+
def Gardner_Altman_Plot_Aesthetic_Adjustments(
1262+
effect_size_type: str,
1263+
plot_data: pd.DataFrame,
1264+
xvar: str,
1265+
yvar: str,
1266+
current_control: str,
1267+
current_group: str,
1268+
rawdata_axes: axes.Axes,
1269+
contrast_axes: axes.Axes,
1270+
results: pd.DataFrame,
1271+
current_effsize: float,
1272+
is_paired: bool,
1273+
one_sankey: bool,
1274+
reflines_kwargs: dict,
1275+
redraw_axes_kwargs: dict
1276+
):
11971277
"""
11981278
Aesthetic adjustments for the Gardner-Altman plot.
11991279
@@ -1382,9 +1462,25 @@ def Gardner_Altman_Plot_Aesthetic_Adjustments(effect_size_type, plot_data, xvar,
13821462
)
13831463

13841464

1385-
def Cumming_Plot_Aesthetic_Adjustments(contrast_axes, reflines_kwargs, is_paired, show_pairs, two_col_sankey, idx, ticks_to_start_twocol_sankey,
1386-
proportional, ticks_to_skip, temp_idx, rawdata_axes, redraw_axes_kwargs, ticks_to_skip_contrast,
1387-
show_delta2, show_mini_meta, horizontal, skip_redraw_lines):
1465+
def Cumming_Plot_Aesthetic_Adjustments(
1466+
contrast_axes: axes.Axes,
1467+
reflines_kwargs: dict,
1468+
is_paired: bool,
1469+
show_pairs: bool,
1470+
two_col_sankey: bool,
1471+
idx: list,
1472+
ticks_to_start_twocol_sankey: list,
1473+
proportional: bool,
1474+
ticks_to_skip: list,
1475+
temp_idx: list,
1476+
rawdata_axes: axes.Axes,
1477+
redraw_axes_kwargs: dict,
1478+
ticks_to_skip_contrast: list,
1479+
show_delta2: bool,
1480+
show_mini_meta: bool,
1481+
horizontal: bool,
1482+
skip_redraw_lines: bool
1483+
):
13881484

13891485
"""
13901486
Aesthetic adjustments for the Cumming plot.
@@ -1535,8 +1631,15 @@ def Cumming_Plot_Aesthetic_Adjustments(contrast_axes, reflines_kwargs, is_paired
15351631
rawdata_axes.set_ylim(swarm_ylim[0]-0.5, swarm_ylim[1])
15361632
contrast_axes.set_ylim(contrast_ylim[0]-0.5, contrast_ylim[1])
15371633

1538-
def Redraw_Spines(rawdata_axes, contrast_axes, redraw_axes_kwargs, float_contrast, horizontal,
1539-
show_delta2, delta2_axes):
1634+
def Redraw_Spines(
1635+
rawdata_axes: axes.Axes,
1636+
contrast_axes: axes.Axes,
1637+
redraw_axes_kwargs: dict,
1638+
float_contrast: bool,
1639+
horizontal: bool,
1640+
show_delta2: bool,
1641+
delta2_axes: axes.Axes
1642+
):
15401643
"""
15411644
Aesthetic general adjustments across both GA and Cumming plots.
15421645
@@ -1610,9 +1713,50 @@ def Redraw_Spines(rawdata_axes, contrast_axes, redraw_axes_kwargs, float_contras
16101713
ax.set_xlim(xlim)
16111714
ax.set_ylim(ylim)
16121715

1613-
def extract_group_summaries(proportional, err_color, rawdata_axes, asymmetric_side, horizontal,
1614-
bootstraps_color_by_group, plot_palette_raw, all_plot_groups,
1615-
n_groups, color_col, ytick_color, group_summaries_kwargs):
1716+
def extract_group_summaries(
1717+
proportional: bool,
1718+
err_color,
1719+
rawdata_axes: axes.Axes,
1720+
asymmetric_side: str,
1721+
horizontal: bool,
1722+
bootstraps_color_by_group: bool,
1723+
plot_palette_raw: list,
1724+
all_plot_groups: list,
1725+
n_groups: int,
1726+
color_col,
1727+
ytick_color,
1728+
group_summaries_kwargs: dict
1729+
):
1730+
"""
1731+
Extract the group summaries for the plotter function.
1732+
1733+
Parameters
1734+
----------
1735+
proportional : bool
1736+
A boolean flag to determine if the plot is for proportional data.
1737+
err_color : str
1738+
The color of the error bars.
1739+
rawdata_axes : object (Axes)
1740+
The raw data axes.
1741+
asymmetric_side : str
1742+
The side of the asymmetric error bars.
1743+
horizontal : bool
1744+
A boolean flag to determine if the plot is for horizontal plotting.
1745+
bootstraps_color_by_group : bool
1746+
A boolean flag to determine if the bootstraps are colored by group.
1747+
plot_palette_raw : list
1748+
A list of the plot palette colors.
1749+
all_plot_groups : list
1750+
A list of all the plot groups.
1751+
n_groups : int
1752+
The number of groups.
1753+
color_col : str
1754+
The name of the color column.
1755+
ytick_color : str
1756+
The color of the y-ticks.
1757+
group_summaries_kwargs : dict
1758+
Kwargs passed to the group summaries.
1759+
"""
16161760

16171761
from .plot_tools import get_swarm_spans
16181762

0 commit comments

Comments
 (0)