This answer to a similar question说明这并不容易,您需要一种解决方法:
如何在holoviews + bokeh中获得带有图例标签的全高垂直线?
您还可以使用此解决方案的一部分:
https ://discourse.holoviz.org/t/horizontal-spikes/117
也许最简单的方法是hv.HLine()
当您想要水平线的图例时不要使用,而是自己创建一条手动线hv.Curve()
:
# import libraries
import pandas as pd
import seaborn as sns
import holoviews as hv
import hvplot.pandas
hv.extension('bokeh')
# create sample dataset
df = sns.load_dataset('anscombe')
# create some horizontal lines manually defining start and end point
manual_horizontal_line = hv.Curve([[0, 10], [15, 10]], label='my_own_line')
another_horizontal_line = hv.Curve([[0, 5], [15, 5]], label='another_line')
# create scatterplot
scatter_plot = df.hvplot.scatter(x='x', y='y', groupby='dataset', dynamic=False)
# overlay manual horizontal lines on scatterplot
scatter_plot * manual_horizontal_line * another_horizontal_line
结果图: