noggin.utils.create_plot

noggin.utils.create_plot(metrics: Union[str, Sequence[str], Dict[str, Union[str, numbers.Real, Sequence[numbers.Real], None]], Dict[str, Dict[str, Union[str, numbers.Real, Sequence[numbers.Real], None]]]], max_fraction_spent_plotting: float = 0.05, last_n_batches: Optional[int] = None, nrows: Optional[int] = None, ncols: int = 1, figsize: Optional[Tuple[int, int]] = None) → Tuple[noggin.plotter.LivePlot, matplotlib.figure.Figure, numpy.ndarray][source]

Create matplotlib figure/axes, and a live-plotter, which publishes “live” training/testing metric data, at a batch and epoch level, to the figure.

Parameters:
metrics : Union[str, Sequence[str], Dict[str, valid-color], Dict[str, Dict[‘train’/’test’, valid-color]]]

The name, or sequence of names, of the metric(s) that will be plotted.

metrics can also be a dictionary, specifying the colors used to plot the metrics. Two mappings are valid:

  • ‘<metric-name>’ -> color-value (specifies train-metric color only)
  • ‘<metric-name>’ -> {‘train’/’test’ : color-value}
max_fraction_spent_plotting : float, optional (default=0.05)

The maximum fraction of time spent plotting. The default value is 0.05, meaning that no more than 5% of processing time will be spent plotting, on average.

last_n_batches : Optional[int]

The maximum number of batches to be plotted at any given time. If None, all data will be plotted.

nrows : Optional[int]

Number of rows of the subplot grid. Metrics are added in row-major order to fill the grid.

ncols : int, optional, default: 1

Number of columns of the subplot grid. Metrics are added in row-major order to fill the grid.

figsize : Optional[Sequence[float, float]]

Specifies the width and height, respectively, of the figure.

Returns:
Tuple[liveplot.LivePlot, matplotlib.figure.Figure, numpy.ndarray(matplotlib.axes.Axes)]

(LivePlot-instance, figure, array-of-axes)

Examples

Creating a live plot in a Jupyter notebook

>>> %matplotlib notebook
>>> import numpy as np
>>> from noggin import create_plot, save_metrics
>>> metrics = ["accuracy", "loss"]
>>> plotter, fig, ax = create_plot(metrics)
>>> for i, x in enumerate(np.linspace(0, 10, 100)):
...     # training
...     x += np.random.rand(1)*5
...     batch_metrics = {"accuracy": x**2, "loss": 1/x**.5}
...     plotter.set_train_batch(batch_metrics, batch_size=1, plot=True)
...
...     # cue training epoch
...     if i%10 == 0 and i > 0:
...         plotter.plot_train_epoch()
...
...         # cue test-time computations
...         for x in np.linspace(0, 10, 5):
...             x += (np.random.rand(1) - 0.5)*5
...             test_metrics = {"accuracy": x**2}
...             plotter.set_test_batch(test_metrics, batch_size=1)
...         plotter.plot_test_epoch()
...
... plotter.plot()  # ensures final data gets plotted

Saving the logged metrics

>>> save_metrics("./metrics.npz", plotter) # save metrics to numpy-archive