def generate(**kwargs) -> Iterator[GeneratorResult]:
        """Generate metric plots and return them as an iterator.

        Args:
            **kwargs: Keyword arguments passed to the generator.
                Must include ``pl_module`` containing the model metrics.

        Yields:
            Iterator[GeneratorResult]: Generator results containing the plot
                figures and filenames.

        Raises:
            ValueError: If ``pl_module`` is not provided in kwargs.

        Example:
            >>> visualizer = MetricsVisualizer()
            >>> for result in visualizer.generate(pl_module=model):
            ...     # Process the visualization result
            ...     print(result.file_name)
        """
        pl_module: AnomalibModule = kwargs.get("pl_module", None)
        if pl_module is None:
            msg = "`pl_module` must be provided"
            raise ValueError(msg)
        for metrics in (pl_module.image_metrics, pl_module.pixel_metrics):
            for metric in metrics.values():
                # `generate_figure` needs to be defined for every metric that should be plotted automatically
                if hasattr(metric, "generate_figure"):
                    fig, log_name = metric.generate_figure()
                    file_name = f"{metrics.prefix}{log_name}.png"
                    yield GeneratorResult(image=fig, file_name=file_name)
Generate metric plots and return them as an iterator.

        Args:
            **kwargs: Keyword arguments passed to the generator.
                Must include ``pl_module`` containing the model metrics.

        Yields:
            Iterator[GeneratorResult]: Generator results containing the plot
                figures and filenames.

        Raises:
            ValueError: If ``pl_module`` is not provided in kwargs.

        Example:
            >>> visualizer = MetricsVisualizer()
            >>> for result in visualizer.generate(pl_module=model):
            ...     # Process the visualization result
            ...     print(result.file_name)
        
src/anomalib/utils/visualization/metrics.py