Skip to content

Working with Bokeh#

Open in Colab

Bokeh is a Python library for creating interactive visualizations for modern web browsers.

You can log and display Bokeh charts as interactive HTML in the Neptune app.

Bokeh figure in Neptune

See in Neptune  Example script 

Before you start#

Tip

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

Bokeh 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/bokeh-support")
  2. Create a sample figure:

    import numpy as np
    from bokeh.plotting import figure
    
    N = 500
    x = np.linspace(0, 10, N)
    y = np.linspace(0, 10, N)
    xx, yy = np.meshgrid(x, y)
    d = np.sin(xx) * np.cos(yy)
    
    p = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")])
    p.x_range.range_padding = p.y_range.range_padding = 0
    
    # Pass a vector of image data as the 'image' argument
    p.image(
        image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11", level="image"
    )
    p.grid.grid_line_width = 0.5
    
  3. Upload the interactive figure:

    run["interactive_img"].upload(p)
    
  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/bokeh-support/e/BOK-9

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