11import warnings
2- from typing import List , Optional , Union
2+ from typing import List , Optional , Union , Iterator , Dict , Any
33
44import matplotlib .pyplot as plt
55import 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 )
0 commit comments