Skip to content

Working with Plotly#

Open in Colab

Plotly is one of the most common Python graphing libraries for interactive graphs.

You can log interactive 2D and 3D charts generated in Plotly to Neptune.

Plotly figure in Neptune

See in Neptune  Example script 

Before you start#

Tip

To follow the guide without any setup, run the Colab example.

Matplotlib incompatibility

Plotly is not compatible with the latest Matplotlib (3.5.0+) due to the fact that mpl_to_plotly() uses deprecated Matplotlib functionalities.

To use Plotly together with Matplotlib, you may need to downgrade Matplotlib to version 3.2 or upgrade Plotly to 5.0+. For more information, see Plotly issue 1568 and issue 3624 on GitHub.

Plotly logging example#

  1. Import Neptune and start a run:

    import neptune.new as 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/plotly-support")
  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()
    
    Warning

    Always call stop() in interactive environments, such as a Python interpreter or Jupyter notebook. The connection to Neptune is not stopped when the cell has finished executing, but rather when the entire notebook stops.

    If you're running a script, the connection is stopped automatically when the script finishes executing. However, it's a best practice to call stop() when the connection is no longer needed.

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

    Example link: https://app.neptune.ai/common/plotly-support/e/PLOT-2

  6. Find the logged images in the All Metadata section.