Skip to content

Commit c72f0de

Browse files
committed
Added a kwarg to horizontal plots to hide the table ax
1 parent 99ce716 commit c72f0de

9 files changed

Lines changed: 83 additions & 38 deletions

File tree

dabest/_effsize_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,8 @@ def plot(
12171217
Whether or not to plot the effect size plot in a horizontal format.
12181218
horizontal_table_kwargs : dict, default None
12191219
Pass relevant keyword arguments to the horizontal table. If None, the following keywords are passed:
1220-
{'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black', 'text_units' : None,
1221-
'paired_gap_dashes' : False, 'fontsize_label': 12, 'label': 'Δ'}
1220+
{'show: True, 'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black',
1221+
'text_units' : None, 'paired_gap_dashes' : False, 'fontsize_label': 12, 'label': 'Δ'}
12221222
12231223
gridkey_rows : list, default None
12241224
Provide a list of row labels for the gridkey. The supplied idx is

dabest/misc_tools.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def get_kwargs(plot_kwargs, ytick_color):
379379

380380
# Table axes for horizontal plot kwargs.
381381
default_table_kwargs = {
382+
'show': True,
382383
'color' : 'yellow',
383384
'alpha' :0.2,
384385
'fontsize' : 12,
@@ -571,7 +572,7 @@ def get_color_palette(plot_kwargs, plot_data, xvar, show_pairs, idx, all_plot_gr
571572
plot_palette_bar, plot_palette_contrast, plot_palette_sankey)
572573

573574
def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_paired, show_pairs, proportional,
574-
float_contrast, effect_size_type, yvar, horizontal):
575+
float_contrast, effect_size_type, yvar, horizontal, show_table):
575576
"""
576577
Initialize the figure and axes for the plotter function.
577578
@@ -599,8 +600,8 @@ def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_pair
599600
The name of the y-axis variable.
600601
horizontal : bool
601602
A boolean flag to determine if the plot is for horizontal plotting.
602-
redraw_axes_kwargs : dict
603-
Kwargs for the redraw_axes.
603+
show_table : dict
604+
A boolean flag to determine if the table will be shown in horizontal plot.
604605
"""
605606
# Params
606607
fig_size = plot_kwargs["fig_size"]
@@ -655,9 +656,12 @@ def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_pair
655656
contrast_axes = rawdata_axes.inset_axes(
656657
[1+contrast_wspace, 0, (plot_width_ratios[1]/plot_width_ratios[0]), 1]
657658
)
658-
table_axes = rawdata_axes.inset_axes(
659-
[1+contrast_wspace+(plot_width_ratios[1]/plot_width_ratios[0]), 0, (plot_width_ratios[2]/plot_width_ratios[0]), 1]
660-
)
659+
if show_table:
660+
table_axes = rawdata_axes.inset_axes(
661+
[1+contrast_wspace+(plot_width_ratios[1]/plot_width_ratios[0]), 0, (plot_width_ratios[2]/plot_width_ratios[0]), 1]
662+
)
663+
else:
664+
table_axes = None
661665

662666
rawdata_axes.set_position(
663667
[ax_position.x0,
@@ -703,25 +707,26 @@ def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_pair
703707
else:
704708
# Here, we hardcode some figure parameters.
705709
if horizontal:
706-
fig, axx = plt.subplots(
707-
ncols=3, gridspec_kw={'width_ratios' : [1,0.7,0.3], 'wspace' : 0.05}, **init_fig_kwargs
708-
)
709-
fig.patch.set_facecolor(face_color)
710-
710+
if show_table:
711+
fig, axx = plt.subplots(
712+
ncols=3, gridspec_kw={'width_ratios' : [1,0.7,0.3], 'wspace' : 0.05}, **init_fig_kwargs
713+
)
714+
else:
715+
fig, axx = plt.subplots(
716+
ncols=2, gridspec_kw={'width_ratios' : [1,0.7], 'wspace' : 0.05}, **init_fig_kwargs
717+
)
711718
else:
712719
if float_contrast:
713720
fig, axx = plt.subplots(
714721
ncols=2,
715722
gridspec_kw={"width_ratios": width_ratios_ga, "wspace": 0},
716723
**init_fig_kwargs
717724
)
718-
fig.patch.set_facecolor(face_color)
719-
720725
else:
721726
fig, axx = plt.subplots(
722727
nrows=2, gridspec_kw={"hspace": h_space_cummings}, **init_fig_kwargs
723728
)
724-
fig.patch.set_facecolor(face_color)
729+
fig.patch.set_facecolor(face_color)
725730

726731
# Title
727732
title = plot_kwargs["title"]
@@ -730,10 +735,10 @@ def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_pair
730735
fig.suptitle(title, fontsize=fontsize_title)
731736
rawdata_axes = axx[0]
732737
contrast_axes = axx[1]
733-
table_axes = axx[2] if horizontal else None
738+
table_axes = axx[2] if horizontal and show_table else None
734739
rawdata_axes.set_frame_on(False)
735740
contrast_axes.set_frame_on(False)
736-
if horizontal:
741+
if horizontal and show_table:
737742
table_axes.set_frame_on(False)
738743

739744
# Swarmplot ylim (Vertical) or xlim (Horizontal)

dabest/plotter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
163163
effect_size_type=effect_size_type,
164164
yvar=yvar,
165165
horizontal=horizontal,
166+
show_table = table_kwargs['show']
166167
)
167168

168169
# Plotting the rawdata.
@@ -537,7 +538,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
537538
)
538539

539540
# Table Axes for horizontal plots
540-
if horizontal:
541+
if horizontal and table_kwargs['show']:
541542
table_for_horizontal_plots(
542543
effectsize_df = effectsize_df,
543544
ax = table_axes,

nbs/API/effsize_objects.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,8 @@
13761376
" Whether or not to plot the effect size plot in a horizontal format.\n",
13771377
" horizontal_table_kwargs : dict, default None\n",
13781378
" Pass relevant keyword arguments to the horizontal table. If None, the following keywords are passed:\n",
1379-
" {'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black', 'text_units' : None, \n",
1380-
" 'paired_gap_dashes' : False, 'fontsize_label': 12, 'label': 'Δ'}\n",
1379+
" {'show: True, 'color' : 'yellow', 'alpha' :0.2, 'fontsize' : 12, 'text_color' : 'black', \n",
1380+
" 'text_units' : None, 'paired_gap_dashes' : False, 'fontsize_label': 12, 'label': 'Δ'}\n",
13811381
" \n",
13821382
" gridkey_rows : list, default None\n",
13831383
" Provide a list of row labels for the gridkey. The supplied idx is\n",

nbs/API/misc_tools.ipynb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@
432432
"\n",
433433
" # Table axes for horizontal plot kwargs.\n",
434434
" default_table_kwargs = {\n",
435+
" 'show': True,\n",
435436
" 'color' : 'yellow',\n",
436437
" 'alpha' :0.2,\n",
437438
" 'fontsize' : 12,\n",
@@ -624,7 +625,7 @@
624625
" plot_palette_bar, plot_palette_contrast, plot_palette_sankey)\n",
625626
"\n",
626627
"def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_paired, show_pairs, proportional,\n",
627-
" float_contrast, effect_size_type, yvar, horizontal):\n",
628+
" float_contrast, effect_size_type, yvar, horizontal, show_table):\n",
628629
" \"\"\"\n",
629630
" Initialize the figure and axes for the plotter function.\n",
630631
"\n",
@@ -652,8 +653,8 @@
652653
" The name of the y-axis variable.\n",
653654
" horizontal : bool\n",
654655
" A boolean flag to determine if the plot is for horizontal plotting.\n",
655-
" redraw_axes_kwargs : dict\n",
656-
" Kwargs for the redraw_axes.\n",
656+
" show_table : dict\n",
657+
" A boolean flag to determine if the table will be shown in horizontal plot.\n",
657658
" \"\"\"\n",
658659
" # Params\n",
659660
" fig_size = plot_kwargs[\"fig_size\"]\n",
@@ -708,9 +709,12 @@
708709
" contrast_axes = rawdata_axes.inset_axes(\n",
709710
" [1+contrast_wspace, 0, (plot_width_ratios[1]/plot_width_ratios[0]), 1]\n",
710711
" )\n",
711-
" table_axes = rawdata_axes.inset_axes(\n",
712-
" [1+contrast_wspace+(plot_width_ratios[1]/plot_width_ratios[0]), 0, (plot_width_ratios[2]/plot_width_ratios[0]), 1]\n",
713-
" )\n",
712+
" if show_table:\n",
713+
" table_axes = rawdata_axes.inset_axes(\n",
714+
" [1+contrast_wspace+(plot_width_ratios[1]/plot_width_ratios[0]), 0, (plot_width_ratios[2]/plot_width_ratios[0]), 1]\n",
715+
" )\n",
716+
" else:\n",
717+
" table_axes = None\n",
714718
"\n",
715719
" rawdata_axes.set_position(\n",
716720
" [ax_position.x0,\n",
@@ -756,25 +760,26 @@
756760
" else:\n",
757761
" # Here, we hardcode some figure parameters.\n",
758762
" if horizontal:\n",
759-
" fig, axx = plt.subplots(\n",
760-
" ncols=3, gridspec_kw={'width_ratios' : [1,0.7,0.3], 'wspace' : 0.05}, **init_fig_kwargs\n",
761-
" )\n",
762-
" fig.patch.set_facecolor(face_color)\n",
763-
"\n",
763+
" if show_table:\n",
764+
" fig, axx = plt.subplots(\n",
765+
" ncols=3, gridspec_kw={'width_ratios' : [1,0.7,0.3], 'wspace' : 0.05}, **init_fig_kwargs\n",
766+
" )\n",
767+
" else:\n",
768+
" fig, axx = plt.subplots(\n",
769+
" ncols=2, gridspec_kw={'width_ratios' : [1,0.7], 'wspace' : 0.05}, **init_fig_kwargs\n",
770+
" )\n",
764771
" else:\n",
765772
" if float_contrast:\n",
766773
" fig, axx = plt.subplots(\n",
767774
" ncols=2,\n",
768775
" gridspec_kw={\"width_ratios\": width_ratios_ga, \"wspace\": 0},\n",
769776
" **init_fig_kwargs\n",
770777
" )\n",
771-
" fig.patch.set_facecolor(face_color)\n",
772-
"\n",
773778
" else:\n",
774779
" fig, axx = plt.subplots(\n",
775780
" nrows=2, gridspec_kw={\"hspace\": h_space_cummings}, **init_fig_kwargs\n",
776781
" )\n",
777-
" fig.patch.set_facecolor(face_color)\n",
782+
" fig.patch.set_facecolor(face_color)\n",
778783
"\n",
779784
" # Title\n",
780785
" title = plot_kwargs[\"title\"]\n",
@@ -783,10 +788,10 @@
783788
" fig.suptitle(title, fontsize=fontsize_title)\n",
784789
" rawdata_axes = axx[0]\n",
785790
" contrast_axes = axx[1]\n",
786-
" table_axes = axx[2] if horizontal else None\n",
791+
" table_axes = axx[2] if horizontal and show_table else None\n",
787792
" rawdata_axes.set_frame_on(False)\n",
788793
" contrast_axes.set_frame_on(False)\n",
789-
" if horizontal:\n",
794+
" if horizontal and show_table:\n",
790795
" table_axes.set_frame_on(False)\n",
791796
" \n",
792797
" # Swarmplot ylim (Vertical) or xlim (Horizontal)\n",

nbs/API/plotter.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
" effect_size_type=effect_size_type,\n",
221221
" yvar=yvar,\n",
222222
" horizontal=horizontal,\n",
223+
" show_table = table_kwargs['show']\n",
223224
" )\n",
224225
" \n",
225226
" # Plotting the rawdata.\n",
@@ -594,7 +595,7 @@
594595
" )\n",
595596
"\n",
596597
" # Table Axes for horizontal plots\n",
597-
" if horizontal:\n",
598+
" if horizontal and table_kwargs['show']:\n",
598599
" table_for_horizontal_plots(\n",
599600
" effectsize_df = effectsize_df,\n",
600601
" ax = table_axes,\n",
19 KB
Loading

nbs/tests/mpl_image_tests/test_Horizontal_Plots.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,7 @@ def test_413_gridkey_merge_pairs_and_autoparser():
826826
def test_414_gridkey_kwargs_and_autoparser():
827827
return two_groups_unpaired.mean_diff.plot(horizontal=True, gridkey_rows='auto', gridkey_kwargs=gridkey_kwargs);
828828

829+
# Table hide
830+
@pytest.mark.mpl_image_compare(tolerance=8)
831+
def test_415_Horizontal_Table_hide():
832+
return multi_2group_unpaired.mean_diff.plot(horizontal=True, horizontal_table_kwargs={'show': False});

nbs/tutorials/08-horizontal_plot.ipynb

Lines changed: 29 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)