Skip to content

Commit fa9c2d8

Browse files
committed
Add gap to contrast axes zeroline for delta-delta experiments and fix contrast axes xlim bug for delta g
1 parent 62a4dc9 commit fa9c2d8

311 files changed

Lines changed: 66 additions & 24 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: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,15 @@ def set_xaxis_ticks_and_lims(
12271227

12281228
if float_contrast:
12291229
contrast_axes.set_xlim(0.5, 1.5)
1230-
elif show_delta2 or show_mini_meta:
1230+
1231+
if show_delta2:
1232+
if show_pairs:
1233+
rawdata_axes.set_xlim(-0.375, 5.5)
1234+
else:
1235+
rawdata_axes.set_xlim(-0.5, 5.5)
1236+
contrast_axes.set_xlim(rawdata_axes.get_xlim())
1237+
1238+
elif show_mini_meta:
12311239
# Increase the xlim of raw data by 2
12321240
temp = rawdata_axes.get_xlim()
12331241
if show_pairs:
@@ -1529,19 +1537,33 @@ def gardner_altman_adjustments(
15291537
def draw_zeroline(
15301538
ax : axes.Axes,
15311539
horizontal : bool,
1532-
reflines_kwargs : dict
1540+
reflines_kwargs : dict,
1541+
extra_delta : bool,
15331542
):
15341543
# If 0 lies within the ylim of the contrast axes, draw a zero reference line.
1535-
ax_lim = ax.get_xlim() if horizontal else ax.get_ylim()
1536-
method = ax.axvline if horizontal else ax.axhline
1544+
if extra_delta and not horizontal:
1545+
contrast_xlim = [-0.5, 3.5]
1546+
delta2_xlim = [4, 5.5]
1547+
1548+
if ax.get_ylim()[0] < ax.get_ylim()[1]:
1549+
contrast_lim_low, contrast_lim_high = ax.get_ylim()
1550+
else:
1551+
contrast_lim_high, contrast_lim_low = ax.get_ylim()
15371552

1538-
if ax_lim[0] < ax_lim[1]:
1539-
contrast_lim_low, contrast_lim_high = ax_lim
1553+
if contrast_lim_low < 0 < contrast_lim_high:
1554+
ax.hlines(y=0, xmin=contrast_xlim[0], xmax=contrast_xlim[1], **reflines_kwargs)
1555+
ax.hlines(y=0, xmin=delta2_xlim[0], xmax=delta2_xlim[1], **reflines_kwargs)
15401556
else:
1541-
contrast_lim_high, contrast_lim_low = ax_lim
1557+
ax_lim = ax.get_xlim() if horizontal else ax.get_ylim()
1558+
method = ax.axvline if horizontal else ax.axhline
1559+
1560+
if ax_lim[0] < ax_lim[1]:
1561+
contrast_lim_low, contrast_lim_high = ax_lim
1562+
else:
1563+
contrast_lim_high, contrast_lim_low = ax_lim
15421564

1543-
if contrast_lim_low < 0 < contrast_lim_high:
1544-
method(0, **reflines_kwargs)
1565+
if contrast_lim_low < 0 < contrast_lim_high:
1566+
method(0, **reflines_kwargs)
15451567

15461568
def redraw_independent_spines(
15471569
rawdata_axes : axes.Axes,

dabest/plotter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
394394
es_marker_kwargs = es_marker_kwargs,
395395
es_errorbar_kwargs = es_errorbar_kwargs
396396
)
397-
398397
## Contrast bars
399398
contrast_bars = plot_kwargs["contrast_bars"]
400399
if contrast_bars:
@@ -452,7 +451,6 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
452451
proportional = proportional,
453452
horizontal = horizontal,
454453
)
455-
456454
# Plot aesthetic adjustments.
457455
if float_contrast: # For Gardner-Altman (float contrast) plots only.
458456
gardner_altman_adjustments(
@@ -476,7 +474,8 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
476474
draw_zeroline(
477475
ax = contrast_axes,
478476
horizontal = horizontal,
479-
reflines_kwargs = reflines_kwargs
477+
reflines_kwargs = reflines_kwargs,
478+
extra_delta = True if show_delta2 else False,
480479
)
481480
## Axes independent spine lines
482481
is_gridkey = True if plot_kwargs["gridkey_rows"] is not None else False

nbs/API/misc_tools.ipynb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,15 @@
12811281
"\n",
12821282
" if float_contrast:\n",
12831283
" contrast_axes.set_xlim(0.5, 1.5)\n",
1284-
" elif show_delta2 or show_mini_meta:\n",
1284+
"\n",
1285+
" if show_delta2:\n",
1286+
" if show_pairs:\n",
1287+
" rawdata_axes.set_xlim(-0.375, 5.5)\n",
1288+
" else:\n",
1289+
" rawdata_axes.set_xlim(-0.5, 5.5)\n",
1290+
" contrast_axes.set_xlim(rawdata_axes.get_xlim())\n",
1291+
"\n",
1292+
" elif show_mini_meta:\n",
12851293
" # Increase the xlim of raw data by 2\n",
12861294
" temp = rawdata_axes.get_xlim()\n",
12871295
" if show_pairs:\n",
@@ -1583,19 +1591,33 @@
15831591
"def draw_zeroline(\n",
15841592
" ax : axes.Axes,\n",
15851593
" horizontal : bool,\n",
1586-
" reflines_kwargs : dict\n",
1594+
" reflines_kwargs : dict,\n",
1595+
" extra_delta : bool,\n",
15871596
" ):\n",
15881597
" # If 0 lies within the ylim of the contrast axes, draw a zero reference line.\n",
1589-
" ax_lim = ax.get_xlim() if horizontal else ax.get_ylim()\n",
1590-
" method = ax.axvline if horizontal else ax.axhline\n",
1598+
" if extra_delta and not horizontal:\n",
1599+
" contrast_xlim = [-0.5, 3.5]\n",
1600+
" delta2_xlim = [4, 5.5]\n",
1601+
" \n",
1602+
" if ax.get_ylim()[0] < ax.get_ylim()[1]:\n",
1603+
" contrast_lim_low, contrast_lim_high = ax.get_ylim()\n",
1604+
" else:\n",
1605+
" contrast_lim_high, contrast_lim_low = ax.get_ylim()\n",
15911606
"\n",
1592-
" if ax_lim[0] < ax_lim[1]:\n",
1593-
" contrast_lim_low, contrast_lim_high = ax_lim\n",
1607+
" if contrast_lim_low < 0 < contrast_lim_high:\n",
1608+
" ax.hlines(y=0, xmin=contrast_xlim[0], xmax=contrast_xlim[1], **reflines_kwargs)\n",
1609+
" ax.hlines(y=0, xmin=delta2_xlim[0], xmax=delta2_xlim[1], **reflines_kwargs)\n",
15941610
" else:\n",
1595-
" contrast_lim_high, contrast_lim_low = ax_lim\n",
1611+
" ax_lim = ax.get_xlim() if horizontal else ax.get_ylim()\n",
1612+
" method = ax.axvline if horizontal else ax.axhline\n",
1613+
"\n",
1614+
" if ax_lim[0] < ax_lim[1]:\n",
1615+
" contrast_lim_low, contrast_lim_high = ax_lim\n",
1616+
" else:\n",
1617+
" contrast_lim_high, contrast_lim_low = ax_lim\n",
15961618
"\n",
1597-
" if contrast_lim_low < 0 < contrast_lim_high:\n",
1598-
" method(0, **reflines_kwargs)\n",
1619+
" if contrast_lim_low < 0 < contrast_lim_high:\n",
1620+
" method(0, **reflines_kwargs)\n",
15991621
"\n",
16001622
"def redraw_independent_spines(\n",
16011623
" rawdata_axes : axes.Axes,\n",

nbs/API/plotter.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@
451451
" es_marker_kwargs = es_marker_kwargs,\n",
452452
" es_errorbar_kwargs = es_errorbar_kwargs\n",
453453
" )\n",
454-
"\n",
455454
" ## Contrast bars\n",
456455
" contrast_bars = plot_kwargs[\"contrast_bars\"]\n",
457456
" if contrast_bars:\n",
@@ -509,7 +508,6 @@
509508
" proportional = proportional,\n",
510509
" horizontal = horizontal,\n",
511510
" )\n",
512-
"\n",
513511
" # Plot aesthetic adjustments.\n",
514512
" if float_contrast: # For Gardner-Altman (float contrast) plots only.\n",
515513
" gardner_altman_adjustments(\n",
@@ -533,7 +531,8 @@
533531
" draw_zeroline(\n",
534532
" ax = contrast_axes,\n",
535533
" horizontal = horizontal,\n",
536-
" reflines_kwargs = reflines_kwargs\n",
534+
" reflines_kwargs = reflines_kwargs,\n",
535+
" extra_delta = True if show_delta2 else False,\n",
537536
" )\n",
538537
" ## Axes independent spine lines\n",
539538
" is_gridkey = True if plot_kwargs[\"gridkey_rows\"] is not None else False\n",
-3.21 KB
-3.26 KB
-2.76 KB
-9.95 KB
-11 KB
-2.41 KB

0 commit comments

Comments
 (0)