def show_anomalies_from_scores(
    series: TimeSeries,
    anomalies: TimeSeries = None,
    pred_series: TimeSeries = None,
    pred_scores: Union[TimeSeries, Sequence[TimeSeries]] = None,
    window: Union[int, Sequence[int]] = 1,
    names_of_scorers: Union[str, Sequence[str]] = None,
    title: str = None,
    metric: Optional[Literal["AUC_ROC", "AUC_PR"]] = None,
    component_wise: bool = False,
):
    """Plot the results generated by an anomaly model.

    The plot will be composed of the following:
        - the actual series itself with the output of the model (if given)
        - the anomaly score of each scorer. The scorer with different windows will be separated.
        - the actual anomalies, if given.

    If `pred_series` is stochastic (i.e., if it has multiple samples), the function will plot:
        - the mean per timestamp
        - the quantile 0.95 for an upper bound
        - the quantile 0.05 for a lower bound

    Possible to:
        - add a title to the figure with the parameter `title`
        - give personalized names for the scorers with `names_of_scorers`
        - show the results of a metric for each anomaly score (AUC_ROC or AUC_PR), if the actual anomalies is given

    Parameters
    ----------
    series
        The actual series to visualize anomalies from.
    anomalies
        The ground truth of the anomalies (1 if it is an anomaly and 0 if not).
    pred_series
        Output of the model given as input the `series` (can be stochastic).
    pred_scores
        Output of the scorers given the output of the model and `series`.
    window
        Window parameter for each anomaly scores.
        Default: 1. If a list of anomaly scores is given, the same default window will be used for every score.
    names_of_scorers
        Name of the scores. Must be a list of length equal to the number of scorers in the anomaly_model.
        Only effective when `pred_scores` is not `None`.
    title
        Title of the figure
    metric
        Optionally, the name of the metric function to use. Must be one of "AUC_ROC" (Area Under the
        Receiver Operating Characteristic Curve) and "AUC_PR" (Average Precision from scores).
        Only effective when `pred_scores` is not `None`.
        Default: "AUC_ROC".
    component_wise
        If True, will separately plot each component in case of multivariate anomaly detection.
    """
    series = _check_input(
        series,
        name="series",
        num_series_expected=1,
        check_multivariate=component_wise,
    )[0]

    if title is None and pred_scores is not None:
        title = "Anomaly results"

    nbr_plots = 1
    if anomalies is not None:
        nbr_plots = nbr_plots + 1
    elif metric is not None:
        raise_log(
            ValueError("`anomalies` must be given in order to calculate a metric."),
            logger=logger,
        )

    pred_scores = series2seq(pred_scores)
    if pred_scores is not None:
        if names_of_scorers is not None:
            names_of_scorers = (
                [names_of_scorers]
                if isinstance(names_of_scorers, str)
                else names_of_scorers
            )
            if len(names_of_scorers) != len(pred_scores):
                raise_log(
                    ValueError(
                        f"The number of names in `names_of_scorers` must match the "
                        f"number of anomaly score given as input, found "
                        f"{len(names_of_scorers)} and expected {len(pred_scores)}."
                    ),
                    logger=logger,
                )

        window = [window] if isinstance(window, int) else window
        if not all([w > 0 for w in window]):
            raise_log(
                ValueError(
                    "Parameter `window` must be a positive integer, "
                    "or a sequence of positive integers."
                ),
                logger=logger,
            )
        window = window if len(window) > 1 else window * len(pred_scores)
        if len(window) != len(pred_scores):
            raise_log(
                ValueError(
                    f"The number of window in `window` must match the "
                    f"number of anomaly score given as input. One window "
                    f"value for each series. Found length {len(window)}, "
                    f"and expected {len(pred_scores)}."
                ),
                logger=logger,
            )

        if not all([w < len(s) for (w, s) in zip(window, pred_scores)]):
            raise_log(
                ValueError(
                    "Parameter `window` must be an integer or sequence of integers "
                    "with value(s) smaller than the length of the corresponding series "
                    "in `pred_scores`."
                ),
                logger=logger,
            )

        nbr_plots += len(set(window))

    series_width = series.n_components
    if pred_series is not None:
        pred_series = _check_input(
            pred_series,
            name="pred_series",
            width_expected=series_width,
            num_series_expected=1,
            check_multivariate=component_wise,
        )[0]

    if anomalies is not None and component_wise:
        anomalies = _check_input(
            anomalies,
            name="anomalies",
            width_expected=series_width,
            num_series_expected=1,
            check_binary=True,
            check_multivariate=component_wise,
        )[0]

    if pred_scores is not None and component_wise:
        for pred_score in pred_scores:
            _ = _check_input(
                pred_score,
                name="pred_score",
                width_expected=series_width,
                num_series_expected=1,
                check_multivariate=component_wise,
            )[0]

    plots_per_ts = nbr_plots * series_width if component_wise else nbr_plots
    height_ratios = ([2] + [1] * (nbr_plots - 1)) * (plots_per_ts // nbr_plots)
    height_total = 2 * sum(height_ratios)
    fig, axs = plt.subplots(
        nrows=plots_per_ts,
        figsize=(8, height_total),
        sharex=True,
        gridspec_kw={"height_ratios": height_ratios},
    )

    for i in range(series_width if component_wise else 1):
        if component_wise:
            series_ = series[series.components[i]]
            anomalies_ = (
                anomalies[anomalies.components[i]] if anomalies is not None else None
            )
            pred_series_ = (
                pred_series[pred_series.components[i]]
                if pred_series is not None
                else None
            )
            pred_scores_ = (
                [pc[pc.components[i]] for pc in pred_scores]
                if pred_scores is not None
                else None
            )
        else:
            series_ = series
            anomalies_ = anomalies
            pred_series_ = pred_series
            pred_scores_ = pred_scores

        _plot_series_and_anomalies(
            series=series_,
            anomalies=anomalies_,
            pred_series=pred_series_,
            pred_scores=pred_scores_,
            window=window,
            names_of_scorers=names_of_scorers,
            metric=metric,
            axs=axs,
            index_ax=i * nbr_plots,
        )
    # make title fit nicely on plot
    title_height = 0.1
    title_y = 1 - title_height / height_total

    fig.suptitle(title, y=title_y)
    fig.tight_layout()
Plot the results generated by an anomaly model.

    The plot will be composed of the following:
        - the actual series itself with the output of the model (if given)
        - the anomaly score of each scorer. The scorer with different windows will be separated.
        - the actual anomalies, if given.

    If `pred_series` is stochastic (i.e., if it has multiple samples), the function will plot:
        - the mean per timestamp
        - the quantile 0.95 for an upper bound
        - the quantile 0.05 for a lower bound

    Possible to:
        - add a title to the figure with the parameter `title`
        - give personalized names for the scorers with `names_of_scorers`
        - show the results of a metric for each anomaly score (AUC_ROC or AUC_PR), if the actual anomalies is given

    Parameters
    ----------
    series
        The actual series to visualize anomalies from.
    anomalies
        The ground truth of the anomalies (1 if it is an anomaly and 0 if not).
    pred_series
        Output of the model given as input the `series` (can be stochastic).
    pred_scores
        Output of the scorers given the output of the model and `series`.
    window
        Window parameter for each anomaly scores.
        Default: 1. If a list of anomaly scores is given, the same default window will be used for every score.
    names_of_scorers
        Name of the scores. Must be a list of length equal to the number of scorers in the anomaly_model.
        Only effective when `pred_scores` is not `None`.
    title
        Title of the figure
    metric
        Optionally, the name of the metric function to use. Must be one of "AUC_ROC" (Area Under the
        Receiver Operating Characteristic Curve) and "AUC_PR" (Average Precision from scores).
        Only effective when `pred_scores` is not `None`.
        Default: "AUC_ROC".
    component_wise
        If True, will separately plot each component in case of multivariate anomaly detection.
    
darts/ad/utils.py