Neptune-Matplotlib IntegrationΒΆ

This integration lets you log charts generated in matplotlib, like confusion matrix or distribution, in Neptune.

matplotlib neptune.ai integration

Follow these steps:

  1. Create an experiment:

    import neptune
    
    neptune.init(api_token='ANONYMOUS',project_qualified_name='shared/showroom')
    neptune.create_experiment()
    
  2. Create a matplotlib figure:

    For example:

    # matplotlib figure example 2
    from matplotlib import pyplot
    import numpy
    
    numpy.random.seed(19680801)
    data = numpy.random.randn(2, 100)
    
    figure, axs = pyplot.subplots(2, 2, figsize=(5, 5))
    axs[0, 0].hist(data[0])
    axs[1, 0].scatter(data[0], data[1])
    axs[0, 1].plot(data[0], data[1])
    
  3. Log figure into Neptune:

Log as static image

experiment.log_image('diagrams', figure)

Log as interactive plotly chart

from neptunecontrib.api import log_chart

log_chart(name='matplotlib_figure', chart=figure)

Note

The log_chart function required that plotly is installed as a Python package in the active environment (e.g. with pip install plotly). In the absence of plotly, log_chart silently falls back on logging the chart as a static image.

  1. Explore the results in the Neptune dashboard:

Static image is logged into the logs section:

image

Interactive figure is logged as artifact into the charts folder. Check out this experiment in the app.

image

Note

Not all matplotlib charts can be converted to interactive plotly charts. If conversion is not possible, neptune-client will emit a warning and fall back on logging the chart as an image.