code: def plot_history(
      history: Union[
          List[Dict[str, Union[float, int]]], "pd.DataFrame"
      ],
      *,
      metrics: Optional[List[str]] = None,
      labels: Optional[List[str]] = None,
      titles: Optional[Union[List[str], str]] = None,
      axes: Optional[List["matplotlib.axes.Axes"]] = None,
      show: bool = True,
      save: bool = False,
      save_filename_template: str = "{metric}",
      save_directory: Optional[str] = None,
      save_extensions: Union[List[str], Tuple[str]] = ("png",),
      close: Optional[bool] = None,
      fig_kwargs: Optional[Dict[str, Any]] = None,
  ):
      """
      Plot the training history in matplotlib. By default, all metrics are plotted.
  
      Args:
          history (Union[List[Dict[str, Union[float, int]]], pandas.DataFrame]): The training history to plot. Can be
              either a list of dictionary as returned by :func:`~poutyne.Model.fit()` or a Pandas DataFrame as read from a
              CSV output by the :class:`~poutyne.CSVLogger` callback.
          metrics (Optional[List[str]], optional): The list of metrics for which to output the plot. By default, every
              metric in the history is used.
          labels (Optional[List[str]], optional): A list of labels to use for each metric. Must be of the same length as
              ``metrics``. By default, the names in the history are used.
          titles (Optional[Union[List[str], str]], optional): A title or a list of titles to use for each metric. If a
              list, must be of the same length as ``metrics``. If a string, the same title will be used for all plots. By
              default, there is no title.
          axes (Optional[List[matplotlib.axes.Axes]], optional): A list of matplotlib :class:`~matplotlib.axes.Axes` to
              use for each metric. Must be of the same length as ``metrics``. By default, a new figure and an new axe is
              created for each plot.
          show (bool, optional): Whether to show the plots. Defaults to True.
          save (bool, optional): Whether to save the plots. Defaults to False.
          save_filename_template (str, optional): The filename without extension for saving the plot. Should contain
              ``{metric}`` somewhere in it or all the plots will overwrite each other. Defaults to ``'{metric}'``.
          save_directory (Optional[str], optional): The directory to save the plots. Default to the current directory.
          save_extensions (Union[List[str], Tuple[str]], optional): A list of extensions under which to save the plots.
              Defaults to `('png', )`.
          close (Optional[bool], optional): Whether to close the matplotlib figures. By default, the figures are closed
              except when in Jupyter notebooks.
          fig_kwargs (Optional[Dict[str, Any]], optional): Any keyword arguments to pass to
              :func:`~matplotlib.pyplot.subplots`.
  
      Returns:
          Tuple[List[matplotlib.figure.Figure], List[matplotlib.axes.Axes]]: A tuple ``(figs, axes)``  where ``figs`` is
          the list of instanciated matplotlib :class:`~matplotlib.figure.Figure` and ``axes`` is a list of instanciated
          matplotlib :class:`~matplotlib.figure.Axes`.
      """
  
      # pylint: disable=too-many-locals
      _raise_error_if_matplotlib_not_there()
  
      metrics = _infer_metrics(history, metrics)
  
      _assert_list_length_with_num_metrics(labels, metrics, "label")
  
      if isinstance(titles, str):
          titles = [titles] * len(metrics)
      else:
          _assert_list_length_with_num_metrics(titles, metrics, "title")
  
      _assert_list_length_with_num_metrics(axes, metrics, "axe")
  
      labels = _none_to_iterator(labels)
      titles = _none_to_iterator(titles, repeat="")
  
      figs, axes = _get_figs_and_axes(axes, len(metrics), fig_kwargs)
      for metric, label, title, ax in zip(
          metrics, labels, titles, axes
      ):
          plot_metric(history, metric, label=label, title=title, ax=ax)
  
      if save:
          _save_figs(
              figs,
              metrics,
              filename_template=save_filename_template,
              directory=save_directory,
              extensions=save_extensions,
          )
  
      if show:
          _show_figs(figs)
  
      if close is None:
          close = not jupyter
  
      if close:
          _close_figs(figs)
  
      return figs, axes
  
file_path: poutyne/poutyne/plotting.py
imports: import itertools
  import os
  from typing import Any, Dict, List, Optional, Tuple, Union
  from poutyne.utils import is_in_jupyter_notebook
label_desc: Use image node_id 9 for calling a global function with example usage: plot_history(history) and returns: figs,  axes