Skip to content

Commit e1e8d06

Browse files
committed
Merge branch 'propplot' into sankey
Adding proportion plot document into sankey branch
2 parents d322ba1 + 415c669 commit e1e8d06

9 files changed

Lines changed: 345 additions & 19 deletions

File tree

dabest/_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ def load(data, idx=None, x=None, y=None, paired=None, id_col=None,
8282
8383
>>> my_data = dabest.load(df, idx=("Control 1", "Test 1"))
8484
85+
For proportion plot.
86+
>>> np.random.seed(88888)
87+
>>> N = 10
88+
>>> c1 = np.random.binomial(1, 0.2, size=N)
89+
>>> t1 = np.random.binomial(1, 0.5, size=N)
90+
>>> df = pd.DataFrame({'Control 1' : c1, 'Test 1': t1})
91+
>>> my_data = dabest.load(df, idx=("Control 1", "Test 1"),proportional=True)
92+
93+
94+
8595
'''
8696
from ._classes import Dabest
8797

dabest/plotter.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
290290

291291
# Initialise the figure.
292292
# sns.set(context="talk", style='ticks')
293-
init_fig_kwargs = dict(figsize=fig_size, dpi=plot_kwargs["dpi"])
294-
# ,tight_layout=True)
293+
init_fig_kwargs = dict(figsize=fig_size, dpi=plot_kwargs["dpi"]
294+
,tight_layout=True)
295295

296296
width_ratios_ga = [2.5, 1]
297297
h_space_cummings = 0.3
@@ -365,7 +365,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
365365
contrast_axes = axx[1]
366366
rawdata_axes.set_frame_on(False)
367367
contrast_axes.set_frame_on(False)
368-
fig.set_tight_layout(False)
368+
# fig.set_tight_layout(False)
369369

370370
redraw_axes_kwargs = {'colors' : ytick_color,
371371
'facecolors' : ytick_color,
@@ -484,9 +484,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
484484
**swarmplot_kwargs)
485485
else:
486486
# Plot the raw data as a barplot.
487-
df_new = plot_data.copy()
488-
bar1_df = df_new.groupby(xvar).count().reset_index()
489-
bar1_df['proportion'] = [i / j for i, j in zip(bar1_df[yvar], bar1_df[yvar])]
487+
bar1_df = pd.DataFrame({xvar: all_plot_groups, 'proportion': np.ones(len(all_plot_groups))})
490488
bar1 = sns.barplot(data=bar1_df, x=xvar, y="proportion",
491489
ax=rawdata_axes,
492490
order=all_plot_groups,
@@ -780,9 +778,9 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
780778
# Check that the effect size is within the swarm ylims.
781779
if effect_size_type in ["mean_diff", "cohens_d", "hedges_g","cohens_h"]:
782780
control_group_summary = plot_data.groupby(xvar)\
783-
.mean().loc[current_control, yvar]
781+
.mean(numeric_only=True).loc[current_control, yvar]
784782
test_group_summary = plot_data.groupby(xvar)\
785-
.mean().loc[current_group, yvar]
783+
.mean(numeric_only=True).loc[current_group, yvar]
786784
elif effect_size_type == "median_diff":
787785
control_group_summary = plot_data.groupby(xvar)\
788786
.median().loc[current_control, yvar]

dabest/tests/test_10_proportion_plot.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,11 @@
5555
def test_101_gardner_altman_unpaired_propdiff():
5656
return two_groups_unpaired.mean_diff.plot();
5757

58-
@pytest.mark.mpl_image_compare
59-
def test_102_gardner_altman_paired_propdiff():
60-
return two_groups_paired.mean_diff.plot();
61-
6258
@pytest.mark.mpl_image_compare
6359
def test_103_cummings_two_group_unpaired_propdiff():
6460
return two_groups_unpaired.mean_diff.plot(fig_size=(4, 6),
6561
float_contrast=False);
6662

67-
@pytest.mark.mpl_image_compare
68-
def test_104_cummings_two_group_paired_propdiff():
69-
return two_groups_paired.mean_diff.plot(fig_size=(6, 6),
70-
float_contrast=False);
71-
7263
@pytest.mark.mpl_image_compare
7364
def test_105_cummings_multi_group_unpaired__propdiff():
7465
return multi_2group.mean_diff.plot();

docs/source/_images/prop_1.png

19.3 KB
Loading

docs/source/_images/prop_2.png

15.4 KB
Loading

docs/source/_images/prop_3.png

21.1 KB
Loading

docs/source/_images/prop_4.png

18.5 KB
Loading

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
# Add any paths that contain custom static files (such as style sheets) here,
144144
# relative to this directory. They are copied after the builtin static files,
145145
# so a file named "default.css" will overwrite the builtin "default.css".
146-
html_static_path = ['_static/css']
146+
html_static_path = ['_static']
147147

148148

149149

@@ -228,4 +228,4 @@
228228
epub_exclude_files = ['search.html']
229229

230230
def setup(app):
231-
app.add_stylesheet('css/alabaster-custom.css')
231+
app.add_css_file('css/alabaster-custom.css')

0 commit comments

Comments
 (0)