Legend Example#

Download this notebook from GitHub (right-click to download).


URL: https://docs.bokeh.org/en/latest/docs/examples/basic/annotations/legend.html

Most examples work across multiple plotting backends, this example is also available for:

import numpy as np
import holoviews as hv
hv.extension('bokeh')

Defining data#

x = np.linspace(0, 4*np.pi, 100)
y = np.sin(x)

scatter1 = hv.Scatter((x, y), label='sin(x)')
scatter2 = hv.Scatter((x, y*2), label='2*sin(x)').opts(color='orange')
scatter3 = hv.Scatter((x, y*3), label='3*sin(x)').opts(color='green')
scatter4 = hv.Scatter(scatter3).opts(line_color='green', marker='square', fill_alpha=0, size=5)

curve1 = hv.Curve(scatter1)
curve2 = hv.Curve(scatter2).opts(line_dash=(4, 4), color='orange')
curve3 = hv.Curve(scatter3).opts(color='orange')

Plot#

example1 = scatter1 * scatter2 * scatter3
example2 = scatter1 *  curve1 * curve2 * scatter4 * curve3

example1.relabel("Legend Example") + example2.relabel("Another Legend Example")
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).