Skip to content

Commit e8f1176

Browse files
committed
Plotter layout edits and trimming swarm and contrast bar plotters into one function
> Trimmed excess code > Created one function to be used for plotting both the swarm bars and contrast bars >tidied up some code snippets and layout of the plotter code
1 parent 3409610 commit e8f1176

7 files changed

Lines changed: 546 additions & 756 deletions

File tree

dabest/_modidx.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@
122122
'dabest.plot_tools.check_data_matches_labels': ( 'API/plot_tools.html#check_data_matches_labels',
123123
'dabest/plot_tools.py'),
124124
'dabest.plot_tools.color_picker': ('API/plot_tools.html#color_picker', 'dabest/plot_tools.py'),
125-
'dabest.plot_tools.contrast_bars_plotter': ( 'API/plot_tools.html#contrast_bars_plotter',
126-
'dabest/plot_tools.py'),
127125
'dabest.plot_tools.delta_text_plotter': ( 'API/plot_tools.html#delta_text_plotter',
128126
'dabest/plot_tools.py'),
129127
'dabest.plot_tools.effect_size_curve_plotter': ( 'API/plot_tools.html#effect_size_curve_plotter',
@@ -141,8 +139,8 @@
141139
'dabest/plot_tools.py'),
142140
'dabest.plot_tools.summary_bars_plotter': ( 'API/plot_tools.html#summary_bars_plotter',
143141
'dabest/plot_tools.py'),
144-
'dabest.plot_tools.swarm_bars_plotter': ( 'API/plot_tools.html#swarm_bars_plotter',
145-
'dabest/plot_tools.py'),
142+
'dabest.plot_tools.swarm_contrast_bar_plotter': ( 'API/plot_tools.html#swarm_contrast_bar_plotter',
143+
'dabest/plot_tools.py'),
146144
'dabest.plot_tools.swarmplot': ('API/plot_tools.html#swarmplot', 'dabest/plot_tools.py'),
147145
'dabest.plot_tools.table_for_horizontal_plots': ( 'API/plot_tools.html#table_for_horizontal_plots',
148146
'dabest/plot_tools.py'),

dabest/misc_tools.py

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def get_unique_categories(names):
9898

9999
def get_params(
100100
effectsize_df: object,
101-
plot_kwargs: dict
101+
plot_kwargs: dict,
102+
sankey_kwargs: dict
102103
):
103104
"""
104105
Extracts parameters from the `effectsize_df` and `plot_kwargs` objects for use in the plotter function.
@@ -109,6 +110,8 @@ def get_params(
109110
A `dabest` EffectSizeDataFrame object.
110111
plot_kwargs : dict
111112
Kwargs passed to the plot function.
113+
sankey kwargs : dict
114+
Kwargs relating to the sankey diagram plots
112115
"""
113116
plot_data = effectsize_df._plot_data
114117
xvar = effectsize_df.xvar
@@ -140,7 +143,6 @@ def get_params(
140143
# Disable Gardner-Altman plotting if any of the idxs comprise of more than
141144
# two groups or if it is a delta-delta plot.
142145
float_contrast = plot_kwargs["float_contrast"]
143-
# effect_size_type = effectsize_df.effect_size
144146
if len(idx) > 1 or len(idx[0]) > 2:
145147
float_contrast = False
146148

@@ -176,10 +178,30 @@ def get_params(
176178

177179
# Boolean for showing Baseline Curve
178180
show_baseline_ec = plot_kwargs["show_baseline_ec"]
181+
182+
# Sankey details
183+
# We need to extract the `sankey` and `flow` from the kwargs
184+
# to use for varying different kinds of paired proportional plots
185+
# We also don't want to pop the parameter from the kwargs
186+
one_sankey = (
187+
False if is_paired is not None else None
188+
) # Flag to indicate if only one sankey is plotted.
189+
two_col_sankey = (
190+
True if proportional and not one_sankey and sankey_kwargs["sankey"] and not sankey_kwargs["flow"] else False
191+
)
192+
193+
# Asymmetric side for swarmplots
194+
asymmetric_side = (
195+
plot_kwargs["swarm_side"] # Default asymmetric side is right
196+
if plot_kwargs["swarm_side"] is not None
197+
else "right" if not horizontal
198+
else "left"
199+
)
179200

180-
return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
181-
show_delta2, show_mini_meta, float_contrast, show_pairs, group_summaries, err_color, horizontal,
182-
results, halfviolin_alpha, ci_type, x1_level, experiment_label, show_baseline_ec)
201+
return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups,
202+
idx, show_delta2, show_mini_meta, float_contrast, show_pairs, group_summaries, err_color,
203+
horizontal, results, halfviolin_alpha, ci_type, x1_level, experiment_label, show_baseline_ec,
204+
one_sankey, two_col_sankey, asymmetric_side)
183205

184206
def get_kwargs(
185207
plot_kwargs: dict,
@@ -1133,7 +1155,8 @@ def set_xaxis_ticks_and_lims(
11331155
contrast_xtick_labels: list,
11341156
plot_kwargs: dict,
11351157
proportional: bool,
1136-
horizontal: bool):
1158+
horizontal: bool
1159+
):
11371160
"""
11381161
Set the x-axis/yaxis ticks and limits for the plotter function.
11391162
@@ -1709,51 +1732,38 @@ def Redraw_Spines(
17091732
og_xlim_raw, og_ylim_raw = rawdata_axes.get_xlim(), rawdata_axes.get_ylim()
17101733
og_xlim_contrast, og_ylim_contrast = contrast_axes.get_xlim(), contrast_axes.get_ylim()
17111734
if horizontal:
1712-
## Raw axes x spine
1713-
rawdata_axes.hlines(
1714-
og_ylim_raw[0],
1715-
og_xlim_raw[0],
1716-
og_xlim_raw[1],
1717-
**redraw_axes_kwargs
1718-
)
1719-
## Contrast axes x spine
1720-
contrast_axes.hlines(
1721-
og_ylim_contrast[0],
1722-
og_xlim_contrast[0],
1723-
og_xlim_contrast[1],
1724-
**redraw_axes_kwargs
1725-
)
1735+
for current_ax, current_ylim, current_xlim in zip((rawdata_axes, contrast_axes), (og_ylim_raw, og_ylim_contrast),
1736+
(og_xlim_raw, og_xlim_contrast)):
1737+
current_ax.hlines(
1738+
current_ylim[0],
1739+
current_xlim[0],
1740+
current_xlim[1],
1741+
**redraw_axes_kwargs
1742+
)
17261743
else:
1727-
## Raw axes y spine
1728-
rawdata_axes.vlines(
1729-
og_xlim_raw[0],
1730-
og_ylim_raw[0],
1731-
og_ylim_raw[1],
1732-
**redraw_axes_kwargs
1733-
)
1734-
## Contrast axes y spine
1735-
xpos = og_xlim_contrast[1] if float_contrast else og_xlim_contrast[0]
1736-
contrast_axes.vlines(
1737-
xpos,
1738-
og_ylim_contrast[0],
1739-
og_ylim_contrast[1],
1740-
**redraw_axes_kwargs
1741-
)
1744+
for current_ax, current_ylim, current_xlim in zip((rawdata_axes, contrast_axes), (og_ylim_raw, og_ylim_contrast),
1745+
(og_xlim_raw[0], og_xlim_contrast[1] if float_contrast else og_xlim_contrast[0])):
1746+
current_ax.vlines(
1747+
current_xlim,
1748+
current_ylim[0],
1749+
current_ylim[1],
1750+
**redraw_axes_kwargs
1751+
)
17421752

17431753
if show_delta2:
17441754
og_xlim_delta, og_ylim_delta = contrast_axes.get_xlim(), contrast_axes.get_ylim()
17451755
delta2_axes.set_ylim(og_ylim_delta)
1746-
1756+
17471757
delta2_axes.vlines(
17481758
og_xlim_delta[1],
17491759
og_ylim_delta[0],
17501760
og_ylim_delta[1],
17511761
**redraw_axes_kwargs
17521762
)
17531763

1754-
for ax, xlim, ylim in zip([rawdata_axes, contrast_axes], [og_xlim_raw, og_xlim_contrast], [og_ylim_raw, og_ylim_contrast]):
1755-
ax.set_xlim(xlim)
1756-
ax.set_ylim(ylim)
1764+
for current_ax, xlim, ylim in zip([rawdata_axes, contrast_axes], [og_xlim_raw, og_xlim_contrast], [og_ylim_raw, og_ylim_contrast]):
1765+
current_ax.set_xlim(xlim)
1766+
current_ax.set_ylim(ylim)
17571767

17581768
def extract_group_summaries(
17591769
proportional: bool,

0 commit comments

Comments
 (0)