|
187 | 187 | " horizontal,\n",
|
188 | 188 | " marker_size,\n",
|
189 | 189 | " custom_palette,\n",
|
190 |
| - " halfviolin_alpha,\n", |
191 |
| - " halfviolin_desat,\n", |
| 190 | + " contrast_alpha,\n", |
| 191 | + " contrast_desat,\n", |
192 | 192 | " labels,\n",
|
193 | 193 | " labels_rotation,\n",
|
194 | 194 | " labels_fontsize,\n",
|
|
226 | 226 | " if idx is not None:\n",
|
227 | 227 | " if not isinstance(idx, (tuple, list)):\n",
|
228 | 228 | " raise TypeError(\"`idx` must be a tuple or list of integers.\")\n",
|
229 |
| - " # if contrast_type == \"mini_meta\":\n", |
230 |
| - " # raise ValueError(\"The `idx` argument is not applicable to mini-meta analyses.\")\n", |
| 229 | + "\n", |
| 230 | + " msg1 = \"The `idx` argument must have the same length as the number of dabest objects. \"\n", |
| 231 | + " msg2 = \"E.g., If two dabest objects are supplied, there should be two lists within `idx`. \"\n", |
| 232 | + " msg3 = \"E.g., `idx` = [[1,2],[0,1]].\"\n", |
| 233 | + " _total = 0\n", |
| 234 | + " for _group in idx:\n", |
| 235 | + " if isinstance(_group, int | float):\n", |
| 236 | + " raise ValueError(msg1+msg2+msg3)\n", |
| 237 | + " else:\n", |
| 238 | + " _total += 1\n", |
| 239 | + " if _total != len(data):\n", |
| 240 | + " raise ValueError(msg1+msg2+msg3)\n", |
| 241 | + " \n", |
| 242 | + " if idx is not None:\n", |
| 243 | + " number_of_curves_to_plot = sum([len(i) for i in idx])\n", |
| 244 | + " else:\n", |
| 245 | + " if contrast_type == 'delta':\n", |
| 246 | + " number_of_curves_to_plot = sum(len(getattr(i, effect_size).results) for i in data)\n", |
| 247 | + " else:\n", |
| 248 | + " number_of_curves_to_plot = len(data)\n", |
231 | 249 | "\n",
|
232 | 250 | " # Axes\n",
|
233 | 251 | " if ax is not None and not isinstance(ax, plt.Axes):\n",
|
|
255 | 273 | " raise TypeError(\"`marker_size` must be a positive integer or float.\")\n",
|
256 | 274 | "\n",
|
257 | 275 | " # Custom palette\n",
|
258 |
| - " if custom_palette is not None and not isinstance(custom_palette, (dict, list, str, type(None))):\n", |
| 276 | + " if custom_palette is not None and not isinstance(custom_palette, (dict, list, tuple, str, type(None))):\n", |
259 | 277 | " raise TypeError(\"The `custom_palette` must be either a dictionary, list, string, or `None`.\")\n",
|
260 | 278 | " if isinstance(custom_palette, dict) and labels is None:\n",
|
261 | 279 | " raise ValueError(\"The `labels` argument must be provided if `custom_palette` is a dictionary.\")\n",
|
| 280 | + " if isinstance(custom_palette, (list, tuple)) and len(custom_palette) < number_of_curves_to_plot:\n", |
| 281 | + " raise ValueError(\"The `custom_palette` list/tuple must have the same length as the number of `data` provided.\")\n", |
262 | 282 | "\n",
|
263 |
| - "\n", |
264 |
| - " # Halfviolin alpha and desat\n", |
265 |
| - " if not isinstance(halfviolin_alpha, float) or not 0 <= halfviolin_alpha <= 1:\n", |
266 |
| - " raise TypeError(\"`halfviolin_alpha` must be a float between 0 and 1.\")\n", |
| 283 | + " # Contrast alpha and desat\n", |
| 284 | + " if not isinstance(contrast_alpha, float) or not 0 <= contrast_alpha <= 1:\n", |
| 285 | + " raise TypeError(\"`contrast_alpha` must be a float between 0 and 1.\")\n", |
267 | 286 | " \n",
|
268 |
| - " if not isinstance(halfviolin_desat, (float, int)) or not 0 <= halfviolin_desat <= 1:\n", |
269 |
| - " raise TypeError(\"`halfviolin_desat` must be a float between 0 and 1 or an int (1).\")\n", |
| 287 | + " if not isinstance(contrast_desat, (float, int)) or not 0 <= contrast_desat <= 1:\n", |
| 288 | + " raise TypeError(\"`contrast_desat` must be a float between 0 and 1 or an int (1).\")\n", |
270 | 289 | " \n",
|
271 | 290 | "\n",
|
272 | 291 | " # Contrast labels\n",
|
273 | 292 | " if labels is not None and not all(isinstance(label, str) for label in labels):\n",
|
274 | 293 | " raise TypeError(\"The `labels` must be a list of strings or `None`.\")\n",
|
275 | 294 | " \n",
|
276 |
| - " number_of_curves_to_plot = sum([len(i) for i in idx]) if idx is not None else len(data)\n", |
| 295 | + " \n", |
277 | 296 | " if labels is not None and len(labels) != number_of_curves_to_plot:\n",
|
278 | 297 | " raise ValueError(\"`labels` must match the number of `data` provided.\")\n",
|
279 | 298 | " \n",
|
|
420 | 439 | " custom_palette, \n",
|
421 | 440 | " labels, \n",
|
422 | 441 | " number_of_curves_to_plot,\n",
|
423 |
| - " halfviolin_desat\n", |
| 442 | + " contrast_desat\n", |
424 | 443 | " ):\n",
|
425 | 444 | " if custom_palette is not None:\n",
|
426 | 445 | " if isinstance(custom_palette, dict):\n",
|
|
438 | 457 | " )\n",
|
439 | 458 | " else:\n",
|
440 | 459 | " violin_colors = sns.color_palette(n_colors=number_of_curves_to_plot)\n",
|
441 |
| - " violin_colors = [sns.desaturate(color, halfviolin_desat) for color in violin_colors]\n", |
| 460 | + " violin_colors = [sns.desaturate(color, contrast_desat) for color in violin_colors]\n", |
442 | 461 | " return violin_colors\n",
|
443 | 462 | "\n",
|
444 | 463 | "\n",
|
|
452 | 471 | "\n",
|
453 | 472 | " marker_size: int = 10,\n",
|
454 | 473 | " custom_palette: Optional[Union[dict, list, str]] = None,\n",
|
455 |
| - " halfviolin_alpha: float = 0.8,\n", |
456 |
| - " halfviolin_desat: float = 1,\n", |
| 474 | + " contrast_alpha: float = 0.8,\n", |
| 475 | + " contrast_desat: float = 1,\n", |
457 | 476 | "\n",
|
458 | 477 | " labels: list[str] = None,\n",
|
459 | 478 | " labels_rotation: int = None,\n",
|
|
502 | 521 | " Marker size for plotting effect size dots.\n",
|
503 | 522 | " custom_palette : Optional[Union[dict, list, str]], default=None\n",
|
504 | 523 | " Custom color palette for the plot.\n",
|
505 |
| - " halfviolin_alpha : float, default=0.8\n", |
| 524 | + " contrast_alpha : float, default=0.8\n", |
506 | 525 | " Transparency level for violin plots.\n",
|
507 |
| - " halfviolin_desat : float, default=1\n", |
| 526 | + " contrast_desat : float, default=1\n", |
508 | 527 | " Saturation level for violin plots.\n",
|
509 | 528 | " labels : List[str]\n",
|
510 | 529 | " Labels for each contrast. If None, defaults to 'Contrast 1', 'Contrast 2', etc.\n",
|
|
528 | 547 | " Custom y-tick labels for the plot.\n",
|
529 | 548 | " remove_spines : bool, default=True\n",
|
530 | 549 | " If True, removes plot spines (except the relevant dependent variable spine).\n",
|
531 |
| - "\n", |
532 |
| - "\n", |
533 |
| - "\n", |
| 550 | + " delta_text : bool, default=True\n", |
| 551 | + " If True, it adds text next to each curve representing the effect size value.\n", |
| 552 | + " delta_text_kwargs : dict, default=None\n", |
| 553 | + " Additional keyword arguments for the delta_text.\n", |
| 554 | + " contrast_bars : bool, default=True\n", |
| 555 | + " If True, it adds bars from the zeroline to the effect size curve.\n", |
| 556 | + " contrast_bars_kwargs : dict, default=None\n", |
| 557 | + " Additional keyword arguments for the contrast_bars.\n", |
534 | 558 | " violin_kwargs : Optional[dict], default=None\n",
|
535 | 559 | " Additional arguments for violin plot customization.\n",
|
536 | 560 | " zeroline_kwargs : Optional[dict], default=None\n",
|
|
558 | 582 | " horizontal = horizontal,\n",
|
559 | 583 | " marker_size = marker_size,\n",
|
560 | 584 | " custom_palette = custom_palette,\n",
|
561 |
| - " halfviolin_alpha = halfviolin_alpha,\n", |
562 |
| - " halfviolin_desat = halfviolin_desat,\n", |
| 585 | + " contrast_alpha = contrast_alpha,\n", |
| 586 | + " contrast_desat = contrast_desat,\n", |
563 | 587 | " labels = labels,\n",
|
564 | 588 | " labels_rotation = labels_rotation,\n",
|
565 | 589 | " labels_fontsize = labels_fontsize,\n",
|
|
611 | 635 | " )\n",
|
612 | 636 | " halfviolin(\n",
|
613 | 637 | " v, \n",
|
614 |
| - " alpha = halfviolin_alpha, \n", |
| 638 | + " alpha = contrast_alpha, \n", |
615 | 639 | " half = \"bottom\" if horizontal else \"right\",\n",
|
616 | 640 | " )\n",
|
617 | 641 | " \n",
|
|
630 | 654 | " custom_palette = custom_palette, \n",
|
631 | 655 | " labels = labels, \n",
|
632 | 656 | " number_of_curves_to_plot = number_of_curves_to_plot,\n",
|
633 |
| - " halfviolin_desat = halfviolin_desat\n", |
| 657 | + " contrast_desat = contrast_desat\n", |
634 | 658 | " )\n",
|
635 | 659 | " \n",
|
636 | 660 | " for patch, color in zip(v[\"bodies\"], violin_colors):\n",
|
|
0 commit comments