Skip to content

Commit 309834b

Browse files
committed
add custom annotations per facet
1 parent 8f148c1 commit 309834b

3 files changed

Lines changed: 193 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
## v0.6
2+
3+
### v0.6.1
4+
- Add option to give facet-specific annotation parameters, such as to
5+
set custom annotations
6+
27
### v0.6.0
38
#### Features
49
- Add option to skip annotation of non-significant results

statannotations/Annotator.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import warnings
2-
from typing import List, Optional, Union
2+
from typing import List, Optional, Union, Iterator, Dict, Any
33

44
import matplotlib.pyplot as plt
55
import matplotlib.transforms as mtransforms
@@ -816,12 +816,16 @@ def _maybe_warn_about_configuration(self):
816816

817817
def plot_and_annotate_facets(
818818
self, plot: str, plot_params: dict, configuration: dict,
819-
annotation_func: str, *args, annotation_params: dict = None,
819+
annotation_func: str, *args,
820+
annotation_params: dict = None,
821+
annotation_params_each: Optional[
822+
Iterator[Dict[str, Any]]] = None,
820823
ax_op_before: List[Union[str, Optional[list],
821824
Optional[dict]]] = None,
822825
ax_op_after: List[Union[str, Optional[list],
823826
Optional[dict]]] = None,
824-
annotate_params: dict = None, **kwargs):
827+
annotate_params: dict = None,
828+
**kwargs):
825829
"""
826830
Plots using seaborn and annotates in a single call, to be used within
827831
a `FacetGrid`.
@@ -836,6 +840,8 @@ def plot_and_annotate_facets(
836840
* 'set_pvalues'
837841
* 'apply_test'
838842
:param annotation_params: parameters for the annotation function
843+
:param annotation_params_each: parameters for the annotation function to
844+
iterate on to find values for each facet.
839845
:param ax_op_before: list of [func_name, args, kwargs] to apply on `ax`
840846
before annotating
841847
:param ax_op_after: list of [func_name, args, kwargs] to apply on `ax`
@@ -846,14 +852,19 @@ def plot_and_annotate_facets(
846852
"""
847853
annotate_params = empty_dict_if_none(annotate_params)
848854
annotation_params = empty_dict_if_none(annotation_params)
855+
annotation_params_this = (
856+
next(annotation_params_each, {})
857+
if annotation_params_each is not None
858+
else {}
859+
)
849860

850861
ax = getattr(sns, plot)(*args, **plot_params, **kwargs)
851862

852863
_apply_ax_operations(ax, ax_op_before)
853864

854865
self.new_plot(ax, plot=plot, **plot_params, data=kwargs['data'])
855866
self.configure(**configuration)
856-
getattr(self, annotation_func)(**annotation_params)
867+
getattr(self, annotation_func)(annotation_params_this, **annotation_params)
857868
self.annotate(**annotate_params)
858869

859870
_apply_ax_operations(ax, ax_op_after)

usage/example.ipynb

Lines changed: 173 additions & 10 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)