Skip to content

Commit fdcfa0c

Browse files
committed
minor code edits
1 parent f01024c commit fdcfa0c

4 files changed

Lines changed: 54 additions & 96 deletions

File tree

dabest/plot_tools.py

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,30 +1016,22 @@ def contrast_bars_plotter(results: object, ax_to_plot: object, swarm_plot_ax: o
10161016
)
10171017
contrast_bars_kwargs.pop('color')
10181018

1019-
if horizontal:
1020-
for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):
1021-
idx_selector = (
1022-
int(contrast_bars_x)
1023-
if type(contrast_bars_colors) == list
1024-
else unpacked_idx[int(contrast_bars_x)]
1025-
)
1026-
ax_to_plot.add_patch(mpatches.Rectangle((0,contrast_bars_x-0.5),contrast_bars_y, 0.5, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))
1019+
for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):
1020+
idx_selector = (
1021+
int(contrast_bars_x)
1022+
if type(contrast_bars_colors) == list
1023+
else unpacked_idx[int(contrast_bars_x)]
1024+
)
1025+
if horizontal:
1026+
ax_to_plot.add_patch(mpatches.Rectangle((0, contrast_bars_x-0.5), contrast_bars_y, 0.5, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))
1027+
else:
1028+
ax_to_plot.add_patch(mpatches.Rectangle((contrast_bars_x-0.25, 0),0.5, contrast_bars_y, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))
10271029

1028-
if show_mini_meta or show_delta2:
1029-
diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference
1030+
if show_mini_meta or show_delta2:
1031+
diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference
1032+
if horizontal:
10301033
ax_to_plot.add_patch(mpatches.Rectangle((0, max(swarm_plot_ax.get_yticks())-0.5), diff, 0.5, color='black', **contrast_bars_kwargs))
1031-
1032-
else:
1033-
for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):
1034-
idx_selector = (
1035-
int(contrast_bars_x)
1036-
if type(contrast_bars_colors) == list
1037-
else unpacked_idx[int(contrast_bars_x)]
1038-
)
1039-
ax_to_plot.add_patch(mpatches.Rectangle((contrast_bars_x-0.25,0),0.5, contrast_bars_y, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))
1040-
1041-
if show_mini_meta or show_delta2:
1042-
diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference
1034+
else:
10431035
ax_to_plot.add_patch(mpatches.Rectangle((max(swarm_plot_ax.get_xticks())+2-0.25,0),0.5, diff, color='black', **contrast_bars_kwargs))
10441036

10451037
ax_to_plot.set_xlim(og_xlim)
@@ -1104,10 +1096,9 @@ def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,
11041096
ax.set_xlim(og_xlim)
11051097
ax.set_ylim(og_ylim)
11061098

1107-
def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object, ticks_to_plot: list, delta_text_kwargs: dict, color_col: str,
1108-
plot_palette_raw: dict, is_paired: bool, proportional: bool, float_contrast: bool,
1109-
show_mini_meta: bool, mini_meta_delta: object, show_delta2: bool, delta_delta: object,
1110-
idx: list):
1099+
def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object, ticks_to_plot: list, delta_text_kwargs: dict,
1100+
color_col: str, plot_palette_raw: dict, is_paired: bool, proportional: bool, float_contrast: bool,
1101+
show_mini_meta: bool, mini_meta_delta: object, show_delta2: bool, delta_delta: object, idx: list):
11111102
"""
11121103
Add delta text to the contrast plot.
11131104
@@ -1393,7 +1384,7 @@ def slopegraph_plotter(dabest_obj, plot_data, xvar, yvar, color_col, plot_palett
13931384
x_start = x_start + grp_count
13941385

13951386
def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type, rawdata_axes,
1396-
contrast_axes, violinplot_kwargs, halfviolin_alpha, ytick_color,
1387+
contrast_axes, violinplot_kwargs, halfviolin_alpha,
13971388
contrast_xtick_labels, effect_size, show_delta2, plot_kwargs,
13981389
horizontal, es_marker_kwargs, es_errorbar_kwargs):
13991390
"""
@@ -1415,8 +1406,6 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
14151406
Keyword arguments for the violinplot.
14161407
halfviolin_alpha : float
14171408
Alpha value for the half violin.
1418-
ytick_color : str
1419-
Color of the yticks.
14201409
es_marker_size : int
14211410
Size of the effect size marker.
14221411
contrast_xtick_labels : list
@@ -1477,14 +1466,12 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
14771466
contrast_axes.plot(
14781467
effsize_x,
14791468
effsize_y,
1480-
# color=ytick_color,
14811469
**es_marker_kwargs
14821470
)
14831471
# Plot the confidence interval.
14841472
contrast_axes.plot(
14851473
ci_x,
14861474
ci_y,
1487-
# color=ytick_color,
14881475
**es_errorbar_kwargs
14891476
)
14901477

@@ -1531,7 +1518,7 @@ def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type,
15311518

15321519

15331520
def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, violinplot_kwargs, halfviolin_alpha,
1534-
ytick_color, bootstraps_color_by_group, plot_palette_contrast,
1521+
bootstraps_color_by_group, plot_palette_contrast,
15351522
horizontal, es_marker_kwargs, es_errorbar_kwargs,
15361523
idx, is_paired, es_paired_lines, es_paired_lines_kwargs):
15371524
"""
@@ -1551,8 +1538,6 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
15511538
Keyword arguments for the violinplot.
15521539
halfviolin_alpha : float
15531540
Alpha value for the half violin.
1554-
ytick_color : str
1555-
Color of the yticks.
15561541
es_marker_size : int
15571542
Size of the effect size marker.
15581543
bootstraps_color_by_group : bool
@@ -1657,18 +1642,14 @@ def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, vi
16571642
else:
16581643
mean_diffs_for_lines.append(int(0))
16591644

1660-
if horizontal:
1661-
contrast_axes.plot(
1662-
mean_diffs_for_lines,
1663-
group,
1664-
**es_paired_lines_kwargs
1665-
)
1666-
else:
1667-
contrast_axes.plot(
1668-
group,
1669-
mean_diffs_for_lines,
1670-
**es_paired_lines_kwargs
1671-
)
1645+
x_data = mean_diffs_for_lines if horizontal else group
1646+
y_data = group if horizontal else mean_diffs_for_lines
1647+
1648+
contrast_axes.plot(
1649+
x_data,
1650+
y_data,
1651+
**es_paired_lines_kwargs
1652+
)
16721653

16731654
return current_group, current_control, current_effsize, contrast_xtick_labels
16741655

dabest/plotter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
367367
contrast_axes = contrast_axes,
368368
violinplot_kwargs = violinplot_kwargs,
369369
halfviolin_alpha = halfviolin_alpha,
370-
ytick_color = ytick_color,
371370
bootstraps_color_by_group = bootstraps_color_by_group,
372371
plot_palette_contrast = plot_palette_contrast,
373372
horizontal = horizontal,
@@ -390,7 +389,6 @@ def effectsize_df_plotter(effectsize_df: object, **plot_kwargs) -> matplotlib.fi
390389
contrast_axes = contrast_axes,
391390
violinplot_kwargs = violinplot_kwargs,
392391
halfviolin_alpha = halfviolin_alpha,
393-
ytick_color = ytick_color,
394392
contrast_xtick_labels = contrast_xtick_labels,
395393
effect_size = effect_size,
396394
show_delta2 = show_delta2,

nbs/API/plot_tools.ipynb

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,30 +1066,22 @@
10661066
" )\n",
10671067
" contrast_bars_kwargs.pop('color')\n",
10681068
"\n",
1069-
" if horizontal:\n",
1070-
" for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):\n",
1071-
" idx_selector = (\n",
1072-
" int(contrast_bars_x) \n",
1073-
" if type(contrast_bars_colors) == list \n",
1074-
" else unpacked_idx[int(contrast_bars_x)]\n",
1075-
" )\n",
1076-
" ax_to_plot.add_patch(mpatches.Rectangle((0,contrast_bars_x-0.5),contrast_bars_y, 0.5, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))\n",
1069+
" for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):\n",
1070+
" idx_selector = (\n",
1071+
" int(contrast_bars_x) \n",
1072+
" if type(contrast_bars_colors) == list \n",
1073+
" else unpacked_idx[int(contrast_bars_x)]\n",
1074+
" )\n",
1075+
" if horizontal:\n",
1076+
" ax_to_plot.add_patch(mpatches.Rectangle((0, contrast_bars_x-0.5), contrast_bars_y, 0.5, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))\n",
1077+
" else:\n",
1078+
" ax_to_plot.add_patch(mpatches.Rectangle((contrast_bars_x-0.25, 0),0.5, contrast_bars_y, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))\n",
10771079
"\n",
1078-
" if show_mini_meta or show_delta2:\n",
1079-
" diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference\n",
1080+
" if show_mini_meta or show_delta2:\n",
1081+
" diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference\n",
1082+
" if horizontal:\n",
10801083
" ax_to_plot.add_patch(mpatches.Rectangle((0, max(swarm_plot_ax.get_yticks())-0.5), diff, 0.5, color='black', **contrast_bars_kwargs))\n",
1081-
"\n",
1082-
" else:\n",
1083-
" for contrast_bars_x,contrast_bars_y in zip(ticks_to_plot, contrast_means):\n",
1084-
" idx_selector = (\n",
1085-
" int(contrast_bars_x) \n",
1086-
" if type(contrast_bars_colors) == list \n",
1087-
" else unpacked_idx[int(contrast_bars_x)]\n",
1088-
" )\n",
1089-
" ax_to_plot.add_patch(mpatches.Rectangle((contrast_bars_x-0.25,0),0.5, contrast_bars_y, color=contrast_bars_colors[idx_selector], **contrast_bars_kwargs))\n",
1090-
"\n",
1091-
" if show_mini_meta or show_delta2:\n",
1092-
" diff = mini_meta_delta.difference if show_mini_meta else delta_delta.difference\n",
1084+
" else:\n",
10931085
" ax_to_plot.add_patch(mpatches.Rectangle((max(swarm_plot_ax.get_xticks())+2-0.25,0),0.5, diff, color='black', **contrast_bars_kwargs))\n",
10941086
"\n",
10951087
" ax_to_plot.set_xlim(og_xlim)\n",
@@ -1154,10 +1146,9 @@
11541146
" ax.set_xlim(og_xlim)\n",
11551147
" ax.set_ylim(og_ylim)\n",
11561148
"\n",
1157-
"def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object, ticks_to_plot: list, delta_text_kwargs: dict, color_col: str, \n",
1158-
" plot_palette_raw: dict, is_paired: bool, proportional: bool, float_contrast: bool,\n",
1159-
" show_mini_meta: bool, mini_meta_delta: object, show_delta2: bool, delta_delta: object,\n",
1160-
" idx: list):\n",
1149+
"def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: object, ticks_to_plot: list, delta_text_kwargs: dict, \n",
1150+
" color_col: str, plot_palette_raw: dict, is_paired: bool, proportional: bool, float_contrast: bool,\n",
1151+
" show_mini_meta: bool, mini_meta_delta: object, show_delta2: bool, delta_delta: object, idx: list):\n",
11611152
" \"\"\"\n",
11621153
" Add delta text to the contrast plot.\n",
11631154
"\n",
@@ -1443,7 +1434,7 @@
14431434
" x_start = x_start + grp_count\n",
14441435
"\n",
14451436
"def plot_minimeta_or_deltadelta_violins(show_mini_meta, effectsize_df, ci_type, rawdata_axes,\n",
1446-
" contrast_axes, violinplot_kwargs, halfviolin_alpha, ytick_color, \n",
1437+
" contrast_axes, violinplot_kwargs, halfviolin_alpha, \n",
14471438
" contrast_xtick_labels, effect_size, show_delta2, plot_kwargs, \n",
14481439
" horizontal, es_marker_kwargs, es_errorbar_kwargs):\n",
14491440
" \"\"\"\n",
@@ -1465,8 +1456,6 @@
14651456
" Keyword arguments for the violinplot.\n",
14661457
" halfviolin_alpha : float\n",
14671458
" Alpha value for the half violin.\n",
1468-
" ytick_color : str\n",
1469-
" Color of the yticks.\n",
14701459
" es_marker_size : int\n",
14711460
" Size of the effect size marker.\n",
14721461
" contrast_xtick_labels : list\n",
@@ -1527,14 +1516,12 @@
15271516
" contrast_axes.plot(\n",
15281517
" effsize_x,\n",
15291518
" effsize_y,\n",
1530-
" # color=ytick_color,\n",
15311519
" **es_marker_kwargs\n",
15321520
" )\n",
15331521
" # Plot the confidence interval.\n",
15341522
" contrast_axes.plot(\n",
15351523
" ci_x,\n",
15361524
" ci_y,\n",
1537-
" # color=ytick_color,\n",
15381525
" **es_errorbar_kwargs\n",
15391526
" )\n",
15401527
"\n",
@@ -1581,7 +1568,7 @@
15811568
"\n",
15821569
"\n",
15831570
"def effect_size_curve_plotter(ticks_to_plot, results, ci_type, contrast_axes, violinplot_kwargs, halfviolin_alpha, \n",
1584-
" ytick_color, bootstraps_color_by_group, plot_palette_contrast,\n",
1571+
" bootstraps_color_by_group, plot_palette_contrast,\n",
15851572
" horizontal, es_marker_kwargs, es_errorbar_kwargs,\n",
15861573
" idx, is_paired, es_paired_lines, es_paired_lines_kwargs):\n",
15871574
" \"\"\"\n",
@@ -1601,8 +1588,6 @@
16011588
" Keyword arguments for the violinplot.\n",
16021589
" halfviolin_alpha : float\n",
16031590
" Alpha value for the half violin.\n",
1604-
" ytick_color : str\n",
1605-
" Color of the yticks.\n",
16061591
" es_marker_size : int\n",
16071592
" Size of the effect size marker.\n",
16081593
" bootstraps_color_by_group : bool\n",
@@ -1707,18 +1692,14 @@
17071692
" else:\n",
17081693
" mean_diffs_for_lines.append(int(0))\n",
17091694
"\n",
1710-
" if horizontal:\n",
1711-
" contrast_axes.plot(\n",
1712-
" mean_diffs_for_lines,\n",
1713-
" group,\n",
1714-
" **es_paired_lines_kwargs\n",
1715-
" )\n",
1716-
" else:\n",
1717-
" contrast_axes.plot(\n",
1718-
" group, \n",
1719-
" mean_diffs_for_lines,\n",
1720-
" **es_paired_lines_kwargs\n",
1721-
" )\n",
1695+
" x_data = mean_diffs_for_lines if horizontal else group\n",
1696+
" y_data = group if horizontal else mean_diffs_for_lines\n",
1697+
"\n",
1698+
" contrast_axes.plot(\n",
1699+
" x_data, \n",
1700+
" y_data,\n",
1701+
" **es_paired_lines_kwargs\n",
1702+
" )\n",
17221703
"\n",
17231704
" return current_group, current_control, current_effsize, contrast_xtick_labels\n",
17241705
"\n",

nbs/API/plotter.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@
424424
" contrast_axes = contrast_axes, \n",
425425
" violinplot_kwargs = violinplot_kwargs, \n",
426426
" halfviolin_alpha = halfviolin_alpha, \n",
427-
" ytick_color = ytick_color, \n",
428427
" bootstraps_color_by_group = bootstraps_color_by_group,\n",
429428
" plot_palette_contrast = plot_palette_contrast,\n",
430429
" horizontal = horizontal,\n",
@@ -447,7 +446,6 @@
447446
" contrast_axes = contrast_axes, \n",
448447
" violinplot_kwargs = violinplot_kwargs, \n",
449448
" halfviolin_alpha = halfviolin_alpha, \n",
450-
" ytick_color = ytick_color, \n",
451449
" contrast_xtick_labels = contrast_xtick_labels, \n",
452450
" effect_size = effect_size,\n",
453451
" show_delta2 = show_delta2, \n",

0 commit comments

Comments
 (0)