Legend example

URL: http://bokeh.pydata.org/en/latest/docs/gallery/legend.html

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

In [1]:
import numpy as np
import holoviews as hv
hv.extension('matplotlib')

Defining data

In [2]:
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)')
scatter3 = hv.Scatter((x, y*3), label='3*sin(x)')

Plot

In [3]:
example1 = scatter1 * scatter2(style=dict(color='orange')) * scatter3(style=dict(color='green'))
example2 = (
    scatter1 * hv.Curve(scatter1) *
    hv.Curve(scatter2)(style=dict(linestyle='--', color='orange')) *
    scatter3(style=dict(color='green', marker='s')) * hv.Curve(scatter3)
)

example1.relabel("Legend Example") + example2.relabel("Another Legend Example")
Out[3]:

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