Skip to content

How to use Neptune with Plotly#

Open in Colab

Plotly is one of the most common Python graphing libraries for interactive graphs. With Neptune, you can log interactive 2D and 3D charts as well as point clouds.

Plotly figure in Neptune

See in Neptune  Example script 

Before you start#

  • Sign up at neptune.ai/register.
  • Create a project for storing your metadata.
  • Have Plotly and Neptune installed:

    pip install -U plotly neptune
    
    conda install -c conda-forge plotly neptune
    

Tip

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

Plotly 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 plotly.express as px
    
    df = px.data.iris()
    plotly_fig = px.scatter_3d(
        df, x="sepal_length", y="sepal_width", z="petal_width", color="species"
    )
    
  3. Upload the interactive figure:

    run["interactive_img"].upload(plotly_fig)
    
  4. To stop the connection to Neptune and sync all data, call the stop() method:

    run.stop()
    

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

The resulting figure is logged as an HTML object.

You can view it in the All metadata section.