Skip to content

Commit

Permalink
Bug fixes in delta text, summary bars, and swarm bars. Also added add…
Browse files Browse the repository at this point in the history
…itional tutorial info for the added aesthetic features
  • Loading branch information
JAnns98 committed Oct 15, 2024
1 parent eae1792 commit f439607
Show file tree
Hide file tree
Showing 3 changed files with 368 additions and 15 deletions.
14 changes: 7 additions & 7 deletions dabest/plot_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,9 @@ def summary_bars_plotter(summary_bars: list, results: object, ax_to_plot: object
else:
summary_xmin, summary_xmax = ax_to_plot.get_xlim()
summary_bars_colors = (
[summary_bars_kwargs.get('color')]*(max(summary_bars)+1)
[summary_bars_kwargs.get('color')]*(max(ticks_to_plot)+1)
if summary_bars_kwargs.get('color') is not None
else ['black']*(max(summary_bars)+1)
else ['black']*(max(ticks_to_plot)+1)
if color_col is not None or (proportional and is_paired) or is_paired
else list(plot_palette_raw.values())
)
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def swarm_bars_plotter(plot_data: object, xvar: str, yvar: str, ax: object,

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

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

if delta_text_y_coordinates is not None:
if not isinstance(delta_text_y_coordinates, list):
if not isinstance(delta_text_y_coordinates, (list, tuple)) or not all(isinstance(y, (int, float)) for y in delta_text_y_coordinates):
raise TypeError("delta_text_kwargs['y_coordinates'] must be a list of y-coordinates.")
if len(delta_text_y_coordinates) != len(total_ticks):
if len(delta_text_y_coordinates) != total_ticks:
raise ValueError("delta_text_kwargs['y_coordinates'] must have the same length as the number of ticks to plot.")
else:
delta_text_y_coordinates = Delta_Values
Expand Down
14 changes: 7 additions & 7 deletions nbs/API/plot_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -967,9 +967,9 @@
" else:\n",
" summary_xmin, summary_xmax = ax_to_plot.get_xlim()\n",
" summary_bars_colors = (\n",
" [summary_bars_kwargs.get('color')]*(max(summary_bars)+1)\n",
" [summary_bars_kwargs.get('color')]*(max(ticks_to_plot)+1)\n",
" if summary_bars_kwargs.get('color') is not None\n",
" else ['black']*(max(summary_bars)+1)\n",
" else ['black']*(max(ticks_to_plot)+1)\n",
" if color_col is not None or (proportional and is_paired) or is_paired \n",
" else list(plot_palette_raw.values())\n",
" )\n",
Expand Down Expand Up @@ -1098,7 +1098,7 @@
"\n",
" swarm_means = plot_data.groupby(xvar, observed=False)[yvar].mean().reindex(index=swarm_bars_order)\n",
" swarm_bars_colors = (\n",
" [swarm_bars_kwargs.get('color')] * (max(swarm_bars_order) + 1) \n",
" [swarm_bars_kwargs.get('color')] * (len(swarm_bars_order) + 1) \n",
" if swarm_bars_kwargs.get('color') is not None \n",
" else ['black']*(len(swarm_bars_order)+1)\n",
" if color_col is not None or is_paired\n",
Expand Down Expand Up @@ -1182,9 +1182,9 @@
" delta_text_x_adjustment = delta_text_kwargs.get('x_adjust')\n",
"\n",
" if delta_text_x_coordinates is not None:\n",
" if not isinstance(delta_text_x_coordinates, list):\n",
" if not isinstance(delta_text_x_coordinates, (list, tuple)) or not all(isinstance(x, (int, float)) for x in delta_text_x_coordinates):\n",
" raise TypeError(\"delta_text_kwargs['x_coordinates'] must be a list of x-coordinates.\")\n",
" if len(delta_text_x_coordinates) != len(total_ticks):\n",
" if len(delta_text_x_coordinates) != total_ticks:\n",
" raise ValueError(\"delta_text_kwargs['x_coordinates'] must have the same length as the number of ticks to plot.\")\n",
" else:\n",
" delta_text_x_coordinates = ticks_to_plot\n",
Expand All @@ -1201,9 +1201,9 @@
" delta_text_y_coordinates = delta_text_kwargs.get('y_coordinates')\n",
"\n",
" if delta_text_y_coordinates is not None:\n",
" if not isinstance(delta_text_y_coordinates, list):\n",
" if not isinstance(delta_text_y_coordinates, (list, tuple)) or not all(isinstance(y, (int, float)) for y in delta_text_y_coordinates):\n",
" raise TypeError(\"delta_text_kwargs['y_coordinates'] must be a list of y-coordinates.\")\n",
" if len(delta_text_y_coordinates) != len(total_ticks):\n",
" if len(delta_text_y_coordinates) != total_ticks:\n",
" raise ValueError(\"delta_text_kwargs['y_coordinates'] must have the same length as the number of ticks to plot.\")\n",
" else:\n",
" delta_text_y_coordinates = Delta_Values\n",
Expand Down
355 changes: 354 additions & 1 deletion nbs/tutorials/06-plot_aesthetics.ipynb

Large diffs are not rendered by default.

0 comments on commit f439607

Please sign in to comment.