Skip to content

How to use Neptune with Seaborn#

Open in Colab

Seaborn is a library for making statistical graphics in Python. With Neptune, you can log and display Seaborn figures as PNG images.

Seaborn figure in Neptune

See in Neptune  Example script 

Before you start#

Tip

To follow the guide without any setup, run the example notebook in Colab

Seaborn logging example#

  1. Import Neptune and start a run:

    import neptune
    
    run = neptune.init_run() # (1)!
    
    1. If you haven't set up your credentials, you can log anonymously:

      neptune.init_run(
          api_token=neptune.ANONYMOUS_API_TOKEN,
          project="common/plotting",
      )
      
  2. Create a sample figure:

    import seaborn as sns
    
    figure = sns.relplot(...)
    
  3. Log the figure to the run:

    run["seaborn_fig"].upload(figure)
    
    If using neptune <1.9.x

    Seaborn figure support was added in version 1.9.0 of the Neptune client library.

    On older versions, you need to access the .figure property of the Seaborn figure:

    import seaborn as sns
    
    seaborn_fig = ...
    
    # Convert Seaborn object to Matplotlib format (matplotlib.Figure)
    figure = seaborn_fig.figure
    
    # Log figure to run
    run["seaborn-img"].upload(figure)
    
  4. To stop the connection to Neptune and sync all data, call the stop() method:

    run.stop()
    
  5. Run your script as you normally would.

To open the run, click the Neptune link that appears in the console output.

[neptune] [info ] Neptune initialized. Open in the app: https://app.neptune.ai/workspace/project/e/RUN-1

Result

You can find the resulting figure in the Images tab.

Logging a series of Seaborn images#

To log a series of Seaborn figures, use append() inside a loop:

for epoch in range(params["iterations"]):
    seaborn_fig = ...
    run["train/distribution"].append(seaborn_fig)
If using neptune <1.9.x

Seaborn figure support was added in version 1.9.0 of the Neptune client library.

On older versions, you need to access the .figure property of the Seaborn figure:

for epoch in range(params["iterations"]):
    seaborn_fig = ...
    figure = seaborn_fig.figure
    run["train/distribution"].append(figure)