Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Horizontal plots and various additional features, documentation, tutorial, tests, and improving code clarity #193

Merged
merged 48 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
377adab
Starting edits to add horizontal plots
JAnns98 Sep 26, 2024
9f2cced
Further edits to horizontal plotting functionality
JAnns98 Sep 26, 2024
f7bf14f
Further additions to horizontal plot functionality part 2
JAnns98 Sep 26, 2024
2f72fc0
Added barplot functionality to horizontal plots
JAnns98 Sep 27, 2024
f893736
delta-delta and mini meta addition to horizontal plots
JAnns98 Sep 28, 2024
7ab566e
Sankey functionality added to horizontal plots
JAnns98 Sep 28, 2024
9e3ec9e
Major updates to trimming functions and moving code to appropriate lo…
JAnns98 Oct 3, 2024
b613a2f
Further edits to plotter and misc_tools and plot_tools functions. Add…
JAnns98 Oct 5, 2024
df6a5de
updates to plotter
JAnns98 Oct 7, 2024
6feefa2
Minor edits to maintain correct xlim and ylims after plotting functions
JAnns98 Oct 8, 2024
9cadefb
Added Jitter kwarg to slopegraph_kwargs for paired data
JAnns98 Oct 8, 2024
068d3f8
Word change
JAnns98 Oct 8, 2024
d572de9
adding additional xlim reset to contrast_axes
JAnns98 Oct 8, 2024
2c59934
New test images
JAnns98 Oct 8, 2024
523f9dd
Updated nbdev
JAnns98 Oct 8, 2024
1c639f1
Update README.md
JAnns98 Oct 8, 2024
eae1792
Credited help from GitHub user for jitter and edits to adjust table d…
JAnns98 Oct 9, 2024
f439607
Bug fixes in delta text, summary bars, and swarm bars. Also added add…
JAnns98 Oct 15, 2024
0555d22
Added tutorial for horizontal plots and the plot aesthetic changes (c…
JAnns98 Oct 16, 2024
d5cb841
Small modifications to tutorial notebook for plot aesthetics
JAnns98 Oct 16, 2024
6ae54d5
Removed redundant code
JAnns98 Oct 17, 2024
907c965
Modified ylim of horizontal plot for delta-delta, mini-meta, and sank…
JAnns98 Oct 18, 2024
29a1e11
Edits to gridkey and code that is impacted by it (remove spines if gr…
JAnns98 Oct 18, 2024
41306f5
Added changes From Sangyu's PR for gridkey auto parser
JAnns98 Oct 20, 2024
adf9151
updated color selection for swarm bars, contrast bars, and delta text…
JAnns98 Oct 23, 2024
6c60a58
Updated Gridkey function for horizontal plot and delta-delta and mini…
JAnns98 Nov 15, 2024
62b1145
Fixes to delta-delta spine in paired condition and added tutorial inf…
JAnns98 Nov 16, 2024
d768b60
Added gridkey kwargs and some more tutorial info for gridkey
JAnns98 Nov 18, 2024
bb090ae
Added gap_width_percent to group_summary_kwargs so that users can spe…
JAnns98 Nov 19, 2024
02140b1
minor edits to remove redundant code
JAnns98 Nov 19, 2024
fa60e76
Added tutorial for group_summaries (gapped lines) and added more kwar…
JAnns98 Nov 20, 2024
99ce716
Added tests for gridkey, horizontal plots, delta text, summary bars, …
JAnns98 Nov 25, 2024
c72f0de
Added a kwarg to horizontal plots to hide the table ax
JAnns98 Nov 26, 2024
d2848cf
Added additional kwarg, tutorial details, and tests for delta dots.
JAnns98 Nov 28, 2024
5b9430f
Reran tutorials to update the images with the new aesthetic changes
JAnns98 Nov 28, 2024
36ac2b5
Added some tests and updated summary bars to allow full ax span or st…
JAnns98 Nov 28, 2024
b1c78bc
Add counts to prop plots feature and added tests and tutorial details…
JAnns98 Nov 29, 2024
28b23e5
Fixed legend location for horizontal plots and added a bbox kwarg for…
JAnns98 Dec 1, 2024
f01024c
Add es_paired_lines and es_paired_lines_kwargs, and added tutorial an…
JAnns98 Dec 3, 2024
fdcfa0c
minor code edits
JAnns98 Dec 3, 2024
b2e4dab
Adjusted alpha values for swarm and contrast bars
JAnns98 Dec 4, 2024
d254128
fixed color selector for contrast and swarm bars to work properly wit…
JAnns98 Dec 4, 2024
71d0d93
More documentation
JAnns98 Dec 4, 2024
9ebbe4d
Added control lines for the horizontal table ax
JAnns98 Dec 4, 2024
79f2883
Minor tutorial edits
JAnns98 Dec 4, 2024
8757b26
Bug fix for custom palette dictionary in delta delta use case
JAnns98 Dec 18, 2024
cada3ca
Minor kwarg name change for delta_text_kwargs
JAnns98 Dec 19, 2024
aa61ed2
Merge branch 'vnbdev' into feat-horizontal-plots
Jacobluke- Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# DABEST-Python


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

[![minimal Python
Expand Down
6 changes: 3 additions & 3 deletions dabest/_dabest_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# %% auto 0
__all__ = ['Dabest']

# %% ../nbs/API/dabest_object.ipynb 4
# %% ../nbs/API/dabest_object.ipynb 5
# Import standard data science libraries
from numpy import array, repeat, random, issubdtype, number
import numpy as np
import pandas as pd
from scipy.stats import norm
from scipy.stats import randint

# %% ../nbs/API/dabest_object.ipynb 6
# %% ../nbs/API/dabest_object.ipynb 7
class Dabest(object):

"""
Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(
self.__idx = (idx,)

elif all([isinstance(i, (tuple, list)) for i in idx]):
all_plot_groups = pd.unique([tt for t in idx for tt in t]).tolist()
all_plot_groups = pd.Series([tt for t in idx for tt in t]).unique().tolist()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ayy this one is better than mine


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

Expand Down
103 changes: 78 additions & 25 deletions dabest/_effsize_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,21 +993,16 @@ def plot(
show_delta2=True,
show_mini_meta=True,
group_summaries=None,
group_summaries_offset=0.1,
fig_size=None,
dpi=100,
ax=None,
gridkey_rows=None,
gridkey_merge_pairs=False,
gridkey_show_Ns=True,
gridkey_show_es=True,
swarmplot_kwargs=None,
barplot_kwargs=None,
violinplot_kwargs=None,
slopegraph_kwargs=None,
sankey_kwargs=None,
reflines_kwargs=None,
group_summary_kwargs=None,
group_summaries_kwargs=None,
legend_kwargs=None,
title=None,
fontsize_title=16,
Expand All @@ -1016,7 +1011,7 @@ def plot(
fontsize_contrastxlabel=12,
fontsize_contrastylabel=12,
fontsize_delta2label=12,
#### Contrast bars and delta text and delta dots WIP ####
#### Contrast bars, Swarm bars, delta text, and delta dots WIP ####
contrast_bars=True,
swarm_bars=True,
contrast_bars_kwargs=None,
Expand All @@ -1027,6 +1022,27 @@ def plot(
delta_text_kwargs=None,
delta_dot=True,
delta_dot_kwargs=None,

# Horizontal Plots
horizontal=False,
horizontal_table_kwargs=None,

# Gridkey
gridkey_rows=None,
gridkey_merge_pairs=False,
gridkey_show_Ns=True,
gridkey_show_es=True,
gridkey_delimiters=[';', '>', '_'],
gridkey_kwargs=None,

es_marker_kwargs=None,
es_errorbar_kwargs=None,

prop_sample_counts=False,
prop_sample_counts_kwargs=None,

es_paired_lines=True,
es_paired_lines_kwargs=None,
):
"""
Creates an estimation plot for the effect size of interest.
Expand Down Expand Up @@ -1105,24 +1121,20 @@ def plot(
notched line beside each group. If 'median_quantiles', then the
median and 25th and 75th percentiles of each group is plotted
instead. If 'None', the summaries are not shown.
group_summaries_offset : float, default 0.1
If group summaries are displayed, they will be offset from the raw
data swarmplot groups by this value.
fig_size : tuple, default None
The desired dimensions of the figure as a (length, width) tuple.
dpi : int, default 100
The dots per inch of the resulting figure.
ax : matplotlib.Axes, default None
Provide an existing Axes for the plots to be created. If no Axes is
specified, a new matplotlib Figure will be created.
gridkey_rows : list, default None
Provide a list of row labels for the gridkey. The supplied idx is
checked against the row labels to determine whether the corresponding
cell should be populated or not.
swarmplot_kwargs : dict, default None
Pass any keyword arguments accepted by the seaborn `swarmplot`
command here, as a dict. If None, the following keywords are
passed to sns.swarmplot : {'size':`raw_marker_size`}.
barplot_kwargs : dict, default None
By default, the keyword arguments passed are:
{"estimator": np.mean, "errorbar": plot_kwargs["ci"]}
violinplot_kwargs : dict, default None
Pass any keyword arguments accepted by the matplotlib `
pyplot.violinplot` command here, as a dict. If None, the following
Expand All @@ -1133,7 +1145,7 @@ def plot(
of observations when `show_pairs=True`. Pass any keyword arguments
accepted by matplotlib `plot()` function here, as a dict.
If None, the following keywords are
passed to plot() : {'linewidth':1, 'alpha':0.5}.
passed to plot() : {'linewidth':1, 'alpha':0.5, 'jitter':0, 'jitter_seed':9876543210}.
sankey_kwargs: dict, default None
Whis will change the appearance of the sankey diagram used to depict
paired proportional data when `show_pairs=True` and `proportional=True`.
Expand All @@ -1146,12 +1158,13 @@ def plot(
command here, as a dict. If None, the following keywords are
passed to Axes.hlines : {'linestyle':'solid', 'linewidth':0.75,
'zorder':2, 'color' : default y-tick color}.
group_summary_kwargs : dict, default None
group_summaries_kwargs : dict, default None
Pass any keyword arguments accepted by the matplotlib.lines.Line2D
command here, as a dict. This will change the appearance of the
vertical summary lines for each group, if `group_summaries` is not
'None'. If None, the following keywords are passed to
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3}.
matplotlib.lines.Line2D : {'lw':2, 'alpha':1, 'zorder':3,
'gap_width_percent':1.5, 'offset':0.1, 'color':None}.
legend_kwargs : dict, default None
Pass any keyword arguments accepted by the matplotlib Axes
`legend` command here, as a dict. If None, the following keywords
Expand All @@ -1176,38 +1189,79 @@ def plot(
fontsize_delta2label : float, default 12
Font size for the delta-delta axes ylabel.


contrast_bars : boolean, default True
Whether or not to display the contrast bars.
swarm_bars : boolean, default True
Whether or not to display the swarm bars.
contrast_bars_kwargs : dict, default None
Pass relevant keyword arguments to the contrast bars. Pass any keyword arguments accepted by
matplotlib.patches.Rectangle here, as a string. If None, the following keywords are passed:
{"color": None, "alpha": 0.3}
{"color": None, "zorder":-3}
swarm_bars_kwargs : dict, default None
Pass relevant keyword arguments to the swarm bars. Pass any keyword arguments accepted by
matplotlib.patches.Rectangle here, as a string. If None, the following keywords are passed:
{"color": None, "alpha": 0.3}
{"color": None, "zorder":-3}

summary_bars : list, default None
Pass a list of indices of the contrast objects to have summary bars displayed on the plot.
For example, [0,1] will show summary bars for the first two contrast objects.
summary_bars_kwargs: dict, default None
If None, the following keywords are passed: {"color": None, "alpha": 0.15}
If None, the following keywords are passed: {"span_ax": False, "color": None, "alpha": 0.15, "zorder":-3}
delta_text : boolean, default True
Whether or not to display the text deltas.
delta_text_kwargs : dict, default None
Pass relevant keyword arguments to the delta text. Pass any keyword arguments accepted by
matplotlib.text.Text here, as a string. If None, the following keywords are passed:
{"color": None, "alpha": 1, "fontsize": 10, "ha": 'center', "va": 'center', "rotation": 0,
"x_location": 'right', "x_coordinates": None, "y_coordinates": None}
Use "x_coordinates" and "y_coordinates" if you would like to specify the text locations manually.
"x_location": 'right', "x_coordinates": None, "y_coordinates": None, "x_adjust": 0}
Use "x_coordinates" and "y_coordinates" if you would like to specify the text locations manually.
Use "x_adjust" to adjust the x location of all the texts (positive moves right, negative left).
delta_dot : boolean, default True
Whether or not to display the delta dots on paired or repeated measure plots.
delta_dot_kwargs : dict, default None
Pass relevant keyword arguments. If None, the following keywords are passed:
{"marker": "^", "alpha": 0.5, "zorder": 2, "size": 3, "side": "right"}
{"color": 'k', "marker": "^", "alpha": 0.5, "zorder": -1, "size": 3, "side": "right"}

horizontal : boolean, default False
Whether or not to plot the effect size plot in a horizontal format.
horizontal_table_kwargs : dict, default None
Pass relevant keyword arguments to the horizontal table. If None, the following keywords are passed:
{'show: True, 'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black',
'text_units' : None, 'control_marker' : '-', 'fontsize_label': 12, 'label': 'Δ'}

gridkey_rows : list, default None
Provide a list of row labels for the gridkey. The supplied idx is
checked against the row labels to determine whether the corresponding
cell should be populated or not.
This can also be set to "auto", which will attempt to auto populate the table.
gridkey_kwargs : dict, default None
Pass relevant keyword arguments to the gridkey. If None, the following keywords are passed:
{ 'show_es' : True, # If True, the gridkey will show the effect size of each comparison.
'show_Ns' :True, # If True, the gridkey will show the number of observations in eachgroup.
'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.
'delimiters': [';', '>', '_'], # Delimiters to split the group names.
'marker': "\u25CF", # Marker for the gridkey dots.
}

es_marker_kwargs: dict, default None
Pass relevant keyword arguments to the effectsize marker plotting. If none, the following keywords are passed:
{'marker': 'o', 'size': plot_kwargs['es_marker_size'], 'color': 'black', 'alpha': 1, 'zorder': 1}
es_errorbar_kwargs: dict, default None
Pass relevant keyword arguments to the effectsize errorbar plotting. If none, the following keywords are passed:
{'color': 'black', 'lw': 2, 'linestyle': '-', 'alpha': 1,'zorder': 1,}

prop_sample_counts: bool, default False
Show the sample counts for each group in proportional plots
prop_sample_counts_kwargs: dict, default None
Pass relevant keyword arguments. If None, the following keywords are passed:
{'color': 'k', 'zorder': 5, 'ha': 'center', 'va': 'center'},

es_paired_lines: bool, default True
Whether or not to add lines to connect the effect size curves in paired plots.
es_paired_lines_kwargs: dict, default None
Pass relevant plot keyword arguments. If None, the following keywords are passed:
{"linestyle": "-", "linewidth": 2, "zorder": -2, "color": 'dimgray', "alpha": 1}


Returns
-------
Expand Down Expand Up @@ -1241,7 +1295,6 @@ def plot(
del all_kwargs["self"]

out = effectsize_df_plotter(self, **all_kwargs)

return out

@property
Expand Down
11 changes: 8 additions & 3 deletions dabest/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@
'dabest/misc_tools.py'),
'dabest.misc_tools.Gardner_Altman_Plot_Aesthetic_Adjustments': ( 'API/misc_tools.html#gardner_altman_plot_aesthetic_adjustments',
'dabest/misc_tools.py'),
'dabest.misc_tools.General_Plot_Aesthetic_Adjustments': ( 'API/misc_tools.html#general_plot_aesthetic_adjustments',
'dabest/misc_tools.py'),
'dabest.misc_tools.Redraw_Spines': ('API/misc_tools.html#redraw_spines', 'dabest/misc_tools.py'),
'dabest.misc_tools.add_counts_to_ticks': ( 'API/misc_tools.html#add_counts_to_ticks',
'dabest/misc_tools.py'),
'dabest.misc_tools.extract_contrast_plotting_ticks': ( 'API/misc_tools.html#extract_contrast_plotting_ticks',
'dabest/misc_tools.py'),
'dabest.misc_tools.extract_group_summaries': ( 'API/misc_tools.html#extract_group_summaries',
'dabest/misc_tools.py'),
'dabest.misc_tools.get_color_palette': ('API/misc_tools.html#get_color_palette', 'dabest/misc_tools.py'),
'dabest.misc_tools.get_kwargs': ('API/misc_tools.html#get_kwargs', 'dabest/misc_tools.py'),
'dabest.misc_tools.get_params': ('API/misc_tools.html#get_params', 'dabest/misc_tools.py'),
Expand Down Expand Up @@ -105,6 +106,8 @@
'dabest/plot_tools.py'),
'dabest.plot_tools.SwarmPlot._swarm': ('API/plot_tools.html#swarmplot._swarm', 'dabest/plot_tools.py'),
'dabest.plot_tools.SwarmPlot.plot': ('API/plot_tools.html#swarmplot.plot', 'dabest/plot_tools.py'),
'dabest.plot_tools.add_counts_to_prop_plots': ( 'API/plot_tools.html#add_counts_to_prop_plots',
'dabest/plot_tools.py'),
'dabest.plot_tools.barplotter': ('API/plot_tools.html#barplotter', 'dabest/plot_tools.py'),
'dabest.plot_tools.check_data_matches_labels': ( 'API/plot_tools.html#check_data_matches_labels',
'dabest/plot_tools.py'),
Expand All @@ -116,7 +119,7 @@
'dabest/plot_tools.py'),
'dabest.plot_tools.error_bar': ('API/plot_tools.html#error_bar', 'dabest/plot_tools.py'),
'dabest.plot_tools.get_swarm_spans': ('API/plot_tools.html#get_swarm_spans', 'dabest/plot_tools.py'),
'dabest.plot_tools.grid_key_WIP': ('API/plot_tools.html#grid_key_wip', 'dabest/plot_tools.py'),
'dabest.plot_tools.gridkey_plotter': ('API/plot_tools.html#gridkey_plotter', 'dabest/plot_tools.py'),
'dabest.plot_tools.halfviolin': ('API/plot_tools.html#halfviolin', 'dabest/plot_tools.py'),
'dabest.plot_tools.normalize_dict': ('API/plot_tools.html#normalize_dict', 'dabest/plot_tools.py'),
'dabest.plot_tools.plot_minimeta_or_deltadelta_violins': ( 'API/plot_tools.html#plot_minimeta_or_deltadelta_violins',
Expand All @@ -130,5 +133,7 @@
'dabest.plot_tools.swarm_bars_plotter': ( 'API/plot_tools.html#swarm_bars_plotter',
'dabest/plot_tools.py'),
'dabest.plot_tools.swarmplot': ('API/plot_tools.html#swarmplot', 'dabest/plot_tools.py'),
'dabest.plot_tools.table_for_horizontal_plots': ( 'API/plot_tools.html#table_for_horizontal_plots',
'dabest/plot_tools.py'),
'dabest.plot_tools.width_determine': ('API/plot_tools.html#width_determine', 'dabest/plot_tools.py')},
'dabest.plotter': {'dabest.plotter.effectsize_df_plotter': ('API/plotter.html#effectsize_df_plotter', 'dabest/plotter.py')}}}
Loading
Loading