Skip to content

Commit f439607

Browse files
committed
Bug fixes in delta text, summary bars, and swarm bars. Also added additional tutorial info for the added aesthetic features
1 parent eae1792 commit f439607

File tree

3 files changed

+368
-15
lines changed

3 files changed

+368
-15
lines changed

dabest/plot_tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,9 @@ def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object
917917
else:
918918
summary_xmin, summary_xmax = ax_to_plot.get_xlim()
919919
summary_bars_colors = (
920-
[summary_bars_kwargs.get('color')]*(max(summary_bars)+1)
920+
[summary_bars_kwargs.get('color')]*(max(ticks_to_plot)+1)
921921
if summary_bars_kwargs.get('color') is not None
922-
else ['black']*(max(summary_bars)+1)
922+
else ['black']*(max(ticks_to_plot)+1)
923923
if color_col is not None or (proportional and is_paired) or is_paired
924924
else list(plot_palette_raw.values())
925925
)
@@ -1048,7 +1048,7 @@ def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,
10481048

10491049
swarm_means = plot_data.groupby(xvar, observed=False)[yvar].mean().reindex(index=swarm_bars_order)
10501050
swarm_bars_colors = (
1051-
[swarm_bars_kwargs.get('color')] * (max(swarm_bars_order) + 1)
1051+
[swarm_bars_kwargs.get('color')] * (len(swarm_bars_order) + 1)
10521052
if swarm_bars_kwargs.get('color') is not None
10531053
else ['black']*(len(swarm_bars_order)+1)
10541054
if color_col is not None or is_paired
@@ -1132,9 +1132,9 @@ def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: objec
11321132
delta_text_x_adjustment = delta_text_kwargs.get('x_adjust')
11331133

11341134
if delta_text_x_coordinates is not None:
1135-
if not isinstance(delta_text_x_coordinates, list):
1135+
if not isinstance(delta_text_x_coordinates, (list, tuple)) or not all(isinstance(x, (int, float)) for x in delta_text_x_coordinates):
11361136
raise TypeError("delta_text_kwargs['x_coordinates'] must be a list of x-coordinates.")
1137-
if len(delta_text_x_coordinates) != len(total_ticks):
1137+
if len(delta_text_x_coordinates) != total_ticks:
11381138
raise ValueError("delta_text_kwargs['x_coordinates'] must have the same length as the number of ticks to plot.")
11391139
else:
11401140
delta_text_x_coordinates = ticks_to_plot
@@ -1151,9 +1151,9 @@ def delta_text_plotter(results: object, ax_to_plot: object, swarm_plot_ax: objec
11511151
delta_text_y_coordinates = delta_text_kwargs.get('y_coordinates')
11521152

11531153
if delta_text_y_coordinates is not None:
1154-
if not isinstance(delta_text_y_coordinates, list):
1154+
if not isinstance(delta_text_y_coordinates, (list, tuple)) or not all(isinstance(y, (int, float)) for y in delta_text_y_coordinates):
11551155
raise TypeError("delta_text_kwargs['y_coordinates'] must be a list of y-coordinates.")
1156-
if len(delta_text_y_coordinates) != len(total_ticks):
1156+
if len(delta_text_y_coordinates) != total_ticks:
11571157
raise ValueError("delta_text_kwargs['y_coordinates'] must have the same length as the number of ticks to plot.")
11581158
else:
11591159
delta_text_y_coordinates = Delta_Values

nbs/API/plot_tools.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,9 @@
967967
" else:\n",
968968
" summary_xmin, summary_xmax = ax_to_plot.get_xlim()\n",
969969
" summary_bars_colors = (\n",
970-
" [summary_bars_kwargs.get('color')]*(max(summary_bars)+1)\n",
970+
" [summary_bars_kwargs.get('color')]*(max(ticks_to_plot)+1)\n",
971971
" if summary_bars_kwargs.get('color') is not None\n",
972-
" else ['black']*(max(summary_bars)+1)\n",
972+
" else ['black']*(max(ticks_to_plot)+1)\n",
973973
" if color_col is not None or (proportional and is_paired) or is_paired \n",
974974
" else list(plot_palette_raw.values())\n",
975975
" )\n",
@@ -1098,7 +1098,7 @@
10981098
"\n",
10991099
" swarm_means = plot_data.groupby(xvar, observed=False)[yvar].mean().reindex(index=swarm_bars_order)\n",
11001100
" swarm_bars_colors = (\n",
1101-
" [swarm_bars_kwargs.get('color')] * (max(swarm_bars_order) + 1) \n",
1101+
" [swarm_bars_kwargs.get('color')] * (len(swarm_bars_order) + 1) \n",
11021102
" if swarm_bars_kwargs.get('color') is not None \n",
11031103
" else ['black']*(len(swarm_bars_order)+1)\n",
11041104
" if color_col is not None or is_paired\n",
@@ -1182,9 +1182,9 @@
11821182
" delta_text_x_adjustment = delta_text_kwargs.get('x_adjust')\n",
11831183
"\n",
11841184
" if delta_text_x_coordinates is not None:\n",
1185-
" if not isinstance(delta_text_x_coordinates, list):\n",
1185+
" if not isinstance(delta_text_x_coordinates, (list, tuple)) or not all(isinstance(x, (int, float)) for x in delta_text_x_coordinates):\n",
11861186
" raise TypeError(\"delta_text_kwargs['x_coordinates'] must be a list of x-coordinates.\")\n",
1187-
" if len(delta_text_x_coordinates) != len(total_ticks):\n",
1187+
" if len(delta_text_x_coordinates) != total_ticks:\n",
11881188
" raise ValueError(\"delta_text_kwargs['x_coordinates'] must have the same length as the number of ticks to plot.\")\n",
11891189
" else:\n",
11901190
" delta_text_x_coordinates = ticks_to_plot\n",
@@ -1201,9 +1201,9 @@
12011201
" delta_text_y_coordinates = delta_text_kwargs.get('y_coordinates')\n",
12021202
"\n",
12031203
" if delta_text_y_coordinates is not None:\n",
1204-
" if not isinstance(delta_text_y_coordinates, list):\n",
1204+
" if not isinstance(delta_text_y_coordinates, (list, tuple)) or not all(isinstance(y, (int, float)) for y in delta_text_y_coordinates):\n",
12051205
" raise TypeError(\"delta_text_kwargs['y_coordinates'] must be a list of y-coordinates.\")\n",
1206-
" if len(delta_text_y_coordinates) != len(total_ticks):\n",
1206+
" if len(delta_text_y_coordinates) != total_ticks:\n",
12071207
" raise ValueError(\"delta_text_kwargs['y_coordinates'] must have the same length as the number of ticks to plot.\")\n",
12081208
" else:\n",
12091209
" delta_text_y_coordinates = Delta_Values\n",

nbs/tutorials/06-plot_aesthetics.ipynb

Lines changed: 354 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)