只有 1 行的图例不会出现在全息视图中

Legend does not appear in holoviews for only 1 line

我了解到 holoviews for some reasons 无法显示 hv.HLine 的图例。为了解决这个问题,我使用 hv.Curve 创建了一条水平线。我现在想为这条曲线添加一个图例,但它没有出现在图中。但是,如果在叠加层中使用第二条曲线,则会出现图例:

p = pd.DataFrame({'a':[0,1,2,3,4,5],'b':[5,5,5,5,5,5],'c':[4.8,4.8,4.8,4.8,4.8,4.8]})
curve1 = hv.Curve(p,'a','b', label = 'm')
curve2 = hv.Curve(p,'a','c', label = 'n')    

overlay1 = curve1 * curve2

overlay1.relabel("two curves overlay - legend") + curve1.relabel("single curve - no legend")

如何获取一条曲线的图例?

目前 (HoloViews 1.13) 无法直接显示图例 line/curve。

只有在同一图中同时显示的 Overlay(= 2 行或更多行等)才有图例。

最简单的解决方法因此是创建同一行的叠加层:

curve1 = hv.Curve([3, 4, 5], name='just one line')
curve1 * curve1

所以你把相同的line/curve放在同一个图中两次


结果图: