Skip to content

Commit 8c75b03

Browse files
committed
Edited delta-delta and mini-meta (non horizontal) layouts
> Add zeroline gap > Remove white space (bring the extra delta closer) > adjust the figsize to be slightly more narrow > adjust gridkey to remove the extra column (control column for the extra delta), and make the column separate for delta-delta experiments
1 parent fa9c2d8 commit 8c75b03

63 files changed

Lines changed: 244 additions & 100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dabest/misc_tools.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def initialize_fig(
734734
all_groups_count = np.sum([len(i) for i in dabest_obj.idx])
735735
# Increase the width (vertical layout) or height (horizontal layout) for delta-delta or mini-meta graph
736736
if show_delta2 or show_mini_meta:
737-
all_groups_count += 2
737+
all_groups_count += 1
738738

739739
if horizontal:
740740
frac = 0.3 if is_paired or show_mini_meta else 0.5
@@ -1217,7 +1217,7 @@ def set_xaxis_ticks_and_lims(
12171217
contrast_axes.set_xticks(rawdata_axes.get_xticks())
12181218
else:
12191219
temp = rawdata_axes.get_xticks()
1220-
temp = np.append(temp, [max(temp) + 1, max(temp) + 2])
1220+
temp = np.append(temp, [max(temp) + 1])
12211221
contrast_axes.set_xticks(temp)
12221222

12231223
# Lims
@@ -1230,9 +1230,9 @@ def set_xaxis_ticks_and_lims(
12301230

12311231
if show_delta2:
12321232
if show_pairs:
1233-
rawdata_axes.set_xlim(-0.375, 5.5)
1233+
rawdata_axes.set_xlim(-0.375, 4.75)
12341234
else:
1235-
rawdata_axes.set_xlim(-0.5, 5.5)
1235+
rawdata_axes.set_xlim(-0.5, 4.75)
12361236
contrast_axes.set_xlim(rawdata_axes.get_xlim())
12371237

12381238
elif show_mini_meta:
@@ -1241,7 +1241,7 @@ def set_xaxis_ticks_and_lims(
12411241
if show_pairs:
12421242
rawdata_axes.set_xlim(temp[0], temp[1] + 0.5)
12431243
else:
1244-
rawdata_axes.set_xlim(temp[0], temp[1] + 2)
1244+
rawdata_axes.set_xlim(temp[0], temp[1] + 1)
12451245
contrast_axes.set_xlim(rawdata_axes.get_xlim())
12461246
else:
12471247
contrast_axes.set_xlim(rawdata_axes.get_xlim())
@@ -1542,8 +1542,8 @@ def draw_zeroline(
15421542
):
15431543
# If 0 lies within the ylim of the contrast axes, draw a zero reference line.
15441544
if extra_delta and not horizontal:
1545-
contrast_xlim = [-0.5, 3.5]
1546-
delta2_xlim = [4, 5.5]
1545+
contrast_xlim = [-0.5, 3.4]
1546+
delta2_xlim = [3.6, 4.75]
15471547

15481548
if ax.get_ylim()[0] < ax.get_ylim()[1]:
15491549
contrast_lim_low, contrast_lim_high = ax.get_ylim()
@@ -1640,12 +1640,12 @@ def redraw_independent_spines(
16401640
del redraw_axes_kwargs["y"]
16411641

16421642
# Add x-spine line for delta2/mini meta.
1643-
if extra_delta:
1644-
ylim = contrast_axes.get_ylim()
1645-
redraw_axes_kwargs["y"] = ylim[0]
1646-
x_ticks = contrast_axes.get_xticks()
1647-
contrast_axes.hlines(xmin=x_ticks[-2], xmax=x_ticks[-1], **redraw_axes_kwargs)
1648-
del redraw_axes_kwargs["y"]
1643+
# if extra_delta:
1644+
# ylim = contrast_axes.get_ylim()
1645+
# redraw_axes_kwargs["y"] = ylim[0]
1646+
# x_ticks = contrast_axes.get_xticks()
1647+
# contrast_axes.hlines(xmin=x_ticks[-2], xmax=x_ticks[-1], **redraw_axes_kwargs)
1648+
# del redraw_axes_kwargs["y"]
16491649

16501650
def redraw_dependent_spines(
16511651
rawdata_axes: axes.Axes,

dabest/plot_tools.py

Lines changed: 108 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def swarm_contrast_bar_plotter(
10421042
if horizontal:
10431043
ax_to_plot.add_patch(mpatches.Rectangle((0, max(axes[0].get_yticks())-0.5), diff, 0.5, color='black', **bar_kwargs))
10441044
else:
1045-
ax_to_plot.add_patch(mpatches.Rectangle((max(axes[0].get_xticks())+2-0.25, 0), 0.5, diff, color='black', **bar_kwargs))
1045+
ax_to_plot.add_patch(mpatches.Rectangle((max(axes[0].get_xticks())+1-0.25, 0), 0.5, diff, color='black', **bar_kwargs))
10461046

10471047
ax_to_plot.set_xlim(og_xlim)
10481048
ax_to_plot.set_ylim(og_ylim)
@@ -1144,8 +1144,8 @@ def delta_text_plotter(
11441144
X_Adjust = 0.48 if delta_text_x_location == 'right' else -0.38
11451145
X_Adjust += delta_text_x_adjustment
11461146
delta_text_x_coordinates = [x+X_Adjust for x in delta_text_x_coordinates]
1147-
if show_mini_meta: delta_text_x_coordinates.append(max(swarm_plot_ax.get_xticks())+2+X_Adjust)
1148-
if show_delta2: delta_text_x_coordinates.append(max(swarm_plot_ax.get_xticks())+2-0.35)
1147+
if show_mini_meta: delta_text_x_coordinates.append(max(swarm_plot_ax.get_xticks())+1+X_Adjust)
1148+
if show_delta2: delta_text_x_coordinates.append(max(swarm_plot_ax.get_xticks())+1+X_Adjust)
11491149
if show_mini_meta or show_delta2: ticks_to_plot.append(max(ticks_to_plot)+1)
11501150

11511151
# Collect the Y-coordinates for the delta text
@@ -1390,6 +1390,7 @@ def plot_minimeta_or_deltadelta_violins(
13901390
show_delta2: bool,
13911391
plot_kwargs: dict,
13921392
horizontal: bool,
1393+
show_pairs: bool,
13931394
es_marker_kwargs: dict,
13941395
es_errorbar_kwargs: dict
13951396
):
@@ -1424,6 +1425,8 @@ def plot_minimeta_or_deltadelta_violins(
14241425
Keyword arguments for the plot.
14251426
horizontal : bool
14261427
If the plot is horizontal.
1428+
show_pairs : bool
1429+
Whether the data is paired and shown in pairs.
14271430
es_marker_kwargs: dict
14281431
Keyword arguments for the effectsize marker.
14291432
es_errorbar_kwargs: dict
@@ -1450,7 +1453,8 @@ def extract_curve_data(dabest_object):
14501453
effsize_x, effsize_y = difference, [position]
14511454
ci_x, ci_y = [ci_low, ci_high], [position, position]
14521455
else:
1453-
position = max(rawdata_axes.get_xticks()) + 2
1456+
# position = max(rawdata_axes.get_xticks()) + 2
1457+
position = max(rawdata_axes.get_xticks()) + 1
14541458
half = "right"
14551459
effsize_x, effsize_y = [position], difference
14561460
ci_x, ci_y = [position, position], [ci_low, ci_high]
@@ -1489,18 +1493,21 @@ def extract_curve_data(dabest_object):
14891493

14901494
else:
14911495
if show_mini_meta:
1492-
contrast_xtick_labels.extend(["", "Weighted Delta"])
1496+
if show_pairs:
1497+
contrast_xtick_labels.extend(["Weighted\n Delta"])
1498+
else:
1499+
contrast_xtick_labels.extend(["Weighted Delta"])
14931500
elif effect_size == "hedges_g":
1494-
contrast_xtick_labels.extend(["", "Deltas' g"])
1501+
contrast_xtick_labels.extend(["Deltas' g"])
14951502
else:
1496-
contrast_xtick_labels.extend(["", "Delta-Delta"])
1503+
contrast_xtick_labels.extend(["Delta-Delta"])
14971504

14981505
# Create the delta-delta axes.
14991506
if show_delta2 and not horizontal:
15001507
if plot_kwargs["delta2_label"] is not None:
15011508
delta2_label = plot_kwargs["delta2_label"]
15021509
elif effect_size == "mean_diff":
1503-
delta2_label = "Delta - Delta"
1510+
delta2_label = "Delta-Delta"
15041511
else:
15051512
delta2_label = "Deltas' g"
15061513
fontsize_delta2label = plot_kwargs["fontsize_delta2label"]
@@ -1880,23 +1887,45 @@ def gridkey_plotter(
18801887
gridkey_rows = added_group_name + gridkey_rows
18811888
table_cellcols = [[""]*len(table_cellcols[0])] + table_cellcols
18821889

1883-
for group_idx, group_vals in enumerate(table_cellcols):
1884-
if group_idx == 0:
1885-
added_group = ['', gridkey_marker]
1886-
elif gridkey_show_es and (group_idx == len(table_cellcols)-1) and not horizontal:
1887-
added_delta_effectsize = delta_delta.difference if show_delta2 else mini_meta.difference
1888-
added_delta_effectsize_str = np.format_float_positional(
1889-
added_delta_effectsize,
1890-
precision=2,
1891-
sign=True,
1892-
trim="k",
1893-
min_digits=2,
1894-
)
1895-
added_group = ['-', added_delta_effectsize_str]
1896-
else:
1897-
added_group = ['', '']
1898-
for n in added_group:
1899-
group_vals.append(n)
1890+
if not horizontal and show_delta2:
1891+
extra_table_cellcols = [[] for i in range(len(table_cellcols))]
1892+
1893+
for group_idx, group_vals in enumerate(extra_table_cellcols):
1894+
if group_idx == 0:
1895+
added_group = [gridkey_marker]
1896+
elif gridkey_show_es and (group_idx == len(extra_table_cellcols)-1) and not horizontal:
1897+
added_delta_effectsize = delta_delta.difference
1898+
added_delta_effectsize_str = np.format_float_positional(
1899+
added_delta_effectsize,
1900+
precision=2,
1901+
sign=True,
1902+
trim="k",
1903+
min_digits=2,
1904+
)
1905+
added_group = [added_delta_effectsize_str]
1906+
else:
1907+
added_group = ['']
1908+
for n in added_group:
1909+
group_vals.append(n)
1910+
1911+
elif horizontal or show_mini_meta:
1912+
for group_idx, group_vals in enumerate(table_cellcols):
1913+
if group_idx == 0:
1914+
added_group = [gridkey_marker] if not horizontal else [" ", gridkey_marker]
1915+
elif gridkey_show_es and (group_idx == len(table_cellcols)-1) and not horizontal:
1916+
added_delta_effectsize = delta_delta.difference if show_delta2 else mini_meta.difference
1917+
added_delta_effectsize_str = np.format_float_positional(
1918+
added_delta_effectsize,
1919+
precision=2,
1920+
sign=True,
1921+
trim="k",
1922+
min_digits=2,
1923+
)
1924+
added_group = [added_delta_effectsize_str] if not horizontal else ['', added_delta_effectsize_str]
1925+
else:
1926+
added_group = [''] if not horizontal else ['', '']
1927+
for n in added_group:
1928+
group_vals.append(n)
19001929

19011930
# Create the table object
19021931
if horizontal:
@@ -1936,18 +1965,60 @@ def gridkey_plotter(
19361965
)
19371966
else:
19381967
# Plot the table for vertical format
1939-
gridkey = ax_to_plot.table(
1940-
cellText=table_cellcols,
1941-
rowLabels=gridkey_rows,
1942-
cellLoc="center",
1943-
bbox=[
1944-
0,
1945-
-len(gridkey_rows) * 0.1 - 0.05,
1946-
1,
1947-
len(gridkey_rows) * 0.1,
1948-
],
1949-
**{"alpha": 0.5}
1950-
)
1968+
if show_mini_meta:
1969+
gridkey = ax_to_plot.table(
1970+
cellText=table_cellcols,
1971+
rowLabels=gridkey_rows,
1972+
cellLoc="center",
1973+
bbox=[
1974+
0,
1975+
-len(gridkey_rows) * 0.1 - 0.05,
1976+
1,
1977+
len(gridkey_rows) * 0.1,
1978+
],
1979+
**{"alpha": 0.5}
1980+
)
1981+
1982+
elif show_delta2:
1983+
gridkey = ax_to_plot.table(
1984+
cellText=table_cellcols,
1985+
rowLabels=gridkey_rows,
1986+
cellLoc="center",
1987+
bbox=[
1988+
0,
1989+
-len(gridkey_rows) * 0.1 - 0.05,
1990+
0.75,
1991+
len(gridkey_rows) * 0.1,
1992+
],
1993+
**{"alpha": 0.5}
1994+
)
1995+
1996+
extra_gridkey = ax_to_plot.table(
1997+
cellText=extra_table_cellcols,
1998+
cellLoc="center",
1999+
bbox=[
2000+
0.78,
2001+
-len(gridkey_rows) * 0.1 - 0.05,
2002+
0.15,
2003+
len(gridkey_rows) * 0.1,
2004+
],
2005+
**{"alpha": 0.5}
2006+
)
2007+
2008+
else:
2009+
gridkey = ax_to_plot.table(
2010+
cellText=table_cellcols,
2011+
rowLabels=gridkey_rows,
2012+
cellLoc="center",
2013+
bbox=[
2014+
0,
2015+
-len(gridkey_rows) * 0.1 - 0.05,
2016+
1,
2017+
len(gridkey_rows) * 0.1,
2018+
],
2019+
**{"alpha": 0.5}
2020+
)
2021+
19512022
# modifies row label cells
19522023
for cell in gridkey._cells:
19532024
if cell[1] == -1:

dabest/plotter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
391391
show_delta2 = show_delta2,
392392
plot_kwargs = plot_kwargs,
393393
horizontal = horizontal,
394+
show_pairs = show_pairs,
394395
es_marker_kwargs = es_marker_kwargs,
395396
es_errorbar_kwargs = es_errorbar_kwargs
396397
)

nbs/API/misc_tools.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@
788788
" all_groups_count = np.sum([len(i) for i in dabest_obj.idx])\n",
789789
" # Increase the width (vertical layout) or height (horizontal layout) for delta-delta or mini-meta graph\n",
790790
" if show_delta2 or show_mini_meta:\n",
791-
" all_groups_count += 2\n",
791+
" all_groups_count += 1\n",
792792
" \n",
793793
" if horizontal:\n",
794794
" frac = 0.3 if is_paired or show_mini_meta else 0.5\n",
@@ -1271,7 +1271,7 @@
12711271
" contrast_axes.set_xticks(rawdata_axes.get_xticks())\n",
12721272
" else:\n",
12731273
" temp = rawdata_axes.get_xticks()\n",
1274-
" temp = np.append(temp, [max(temp) + 1, max(temp) + 2])\n",
1274+
" temp = np.append(temp, [max(temp) + 1])\n",
12751275
" contrast_axes.set_xticks(temp)\n",
12761276
"\n",
12771277
" # Lims\n",
@@ -1284,9 +1284,9 @@
12841284
"\n",
12851285
" if show_delta2:\n",
12861286
" if show_pairs:\n",
1287-
" rawdata_axes.set_xlim(-0.375, 5.5)\n",
1287+
" rawdata_axes.set_xlim(-0.375, 4.75)\n",
12881288
" else:\n",
1289-
" rawdata_axes.set_xlim(-0.5, 5.5)\n",
1289+
" rawdata_axes.set_xlim(-0.5, 4.75)\n",
12901290
" contrast_axes.set_xlim(rawdata_axes.get_xlim())\n",
12911291
"\n",
12921292
" elif show_mini_meta:\n",
@@ -1295,7 +1295,7 @@
12951295
" if show_pairs:\n",
12961296
" rawdata_axes.set_xlim(temp[0], temp[1] + 0.5)\n",
12971297
" else:\n",
1298-
" rawdata_axes.set_xlim(temp[0], temp[1] + 2)\n",
1298+
" rawdata_axes.set_xlim(temp[0], temp[1] + 1)\n",
12991299
" contrast_axes.set_xlim(rawdata_axes.get_xlim())\n",
13001300
" else:\n",
13011301
" contrast_axes.set_xlim(rawdata_axes.get_xlim())\n",
@@ -1596,8 +1596,8 @@
15961596
" ):\n",
15971597
" # If 0 lies within the ylim of the contrast axes, draw a zero reference line.\n",
15981598
" if extra_delta and not horizontal:\n",
1599-
" contrast_xlim = [-0.5, 3.5]\n",
1600-
" delta2_xlim = [4, 5.5]\n",
1599+
" contrast_xlim = [-0.5, 3.4]\n",
1600+
" delta2_xlim = [3.6, 4.75]\n",
16011601
" \n",
16021602
" if ax.get_ylim()[0] < ax.get_ylim()[1]:\n",
16031603
" contrast_lim_low, contrast_lim_high = ax.get_ylim()\n",
@@ -1694,12 +1694,12 @@
16941694
" del redraw_axes_kwargs[\"y\"]\n",
16951695
"\n",
16961696
" # Add x-spine line for delta2/mini meta.\n",
1697-
" if extra_delta:\n",
1698-
" ylim = contrast_axes.get_ylim()\n",
1699-
" redraw_axes_kwargs[\"y\"] = ylim[0]\n",
1700-
" x_ticks = contrast_axes.get_xticks()\n",
1701-
" contrast_axes.hlines(xmin=x_ticks[-2], xmax=x_ticks[-1], **redraw_axes_kwargs)\n",
1702-
" del redraw_axes_kwargs[\"y\"]\n",
1697+
" # if extra_delta:\n",
1698+
" # ylim = contrast_axes.get_ylim()\n",
1699+
" # redraw_axes_kwargs[\"y\"] = ylim[0]\n",
1700+
" # x_ticks = contrast_axes.get_xticks()\n",
1701+
" # contrast_axes.hlines(xmin=x_ticks[-2], xmax=x_ticks[-1], **redraw_axes_kwargs)\n",
1702+
" # del redraw_axes_kwargs[\"y\"]\n",
17031703
" \n",
17041704
"def redraw_dependent_spines(\n",
17051705
" rawdata_axes: axes.Axes, \n",

0 commit comments

Comments
 (0)