Ben Chuanlong Du's Blog

It is never too late to learn.

Legend of Plots in HoloViews

In [57]:
import numpy as np
import holoviews as hv

hv.extension("bokeh")
In [58]:
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)")
In [59]:
example1 = scatter1 * scatter2.options(color="orange") * scatter3.options(color="green")
example2 = (
    scatter1
    * hv.Curve(scatter1)
    * hv.Curve(scatter2).options(line_dash=(4, 4), color="orange")
    * scatter3.options(line_color="green", marker="square", fill_alpha=0, size=5)
    * hv.Curve(scatter3)
)

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

Comments