def plot_and_annotate_facets( self, plot: str, plot_params: dict, configuration: dict, annotation_func: str, *args, annotation_params: dict = None, ax_op_before: List[Union[str, Optional[list], Optional[dict]]] = None, ax_op_after: List[Union[str, Optional[list], Optional[dict]]] = None, annotate_params: dict = None, **kwargs): """ Plots using seaborn and annotates in a single call, to be used within a `FacetGrid`. First, initialize the Annotator with `Annotator(None, pairs)` to define the pairs, then map this function onto the `FacetGrid`. :param plot: seaborn plotting function to call :param plot_params: parameters for plotting function call :param configuration: parameters for Annotator.configure :param annotation_func: name of annotation function to be called, from: * 'set_custom_annotations' * 'set_pvalues' * 'apply_test' :param annotation_params: parameters for the annotation function :param ax_op_before: list of [func_name, args, kwargs] to apply on `ax` before annotating :param ax_op_after: list of [func_name, args, kwargs] to apply on `ax` after annotating :param annotate_params: parameters for `Annotator.annotate` :param args: additional parameters for the seaborn function :param kwargs: additional parameters for the seaborn function """ annotate_params = empty_dict_if_none(annotate_params) annotation_params = empty_dict_if_none(annotation_params) ax = getattr(sns, plot)(*args, **plot_params, **kwargs) _apply_ax_operations(ax, ax_op_before) self.new_plot(ax, plot=plot, **plot_params, data=kwargs['data']) self.configure(**configuration) getattr(self, annotation_func)(**annotation_params) self.annotate(**annotate_params) _apply_ax_operations(ax, ax_op_after) return self._get_output()
def _apply_ax_operations(ax, operations): if operations is None: return for operation in operations: _ensure_ax_operation_format(operation) getattr(ax, operation[0])(*operation[1], **empty_dict_if_none(operation[2]))
def plot_and_annotate(plot: str, pairs: list, plot_params: dict, configuration: dict, annotation_func: str, annotation_params: dict = None, ax_op_before: List[Union[str, Optional[list], Optional[dict]]] = None, ax_op_after: List[Union[str, Optional[list], Optional[dict]]] = None, annotate_params: dict = None): """ Plots using seaborn and annotates in a single call. :param plot: seaborn plotting function to call :param pairs: pairs to compare (see Annotator) :param plot_params: parameters for plotting function call :param configuration: parameters for Annotator.configure :param annotation_func: name of annotation function to be called, from: * 'set_custom_annotations' * 'set_pvalues' * 'apply_test' :param annotation_params: parameters for the annotation function :param ax_op_before: list of [func_name, args, kwargs] to apply on `ax` before annotating :param ax_op_after: list of [func_name, args, kwargs] to apply on `ax` after annotating :param annotate_params: parameters for `Annotator.annotate` """ annotate_params = empty_dict_if_none(annotate_params) annotation_params = empty_dict_if_none(annotation_params) ax = getattr(sns, plot)(**plot_params) _apply_ax_operations(ax, ax_op_before) annotator = Annotator(ax, pairs, plot=plot, **plot_params) annotator.configure(**configuration) getattr(annotator, annotation_func)(**annotation_params) annotator.annotate(**annotate_params) _apply_ax_operations(ax, ax_op_after) return (*annotator._get_output(), annotator)