[英]HoloViews Area Overlay Axes and Labels
我正在嘗試覆蓋Scatter
和Area
,但是后者導致軸及其標簽消失。
import pandas as pd
import holoviews as hv
hv.extension('bokeh')
from bokeh.models import HoverTool
data = dict(A=["A1", "A1", "A1", "A1"], B=["B1", "B1", "B1", "B2"], C=[10, -5, 23, 9], D=[0, 5, -7, 6])
df = pd.DataFrame(data=data)
df_hv = hv.Dataset(df)
hover = HoverTool(
tooltips=[("C", "@C{0,.0}"),
("D", "@D{0,.0}")]
)
scatter = df_hv.to(hv.Scatter, kdims=["C", "D"], vdims=["C", "D"], groupby=["A", "B"]).redim.label(x="A (unitA)", y="B (unitB)")
area = hv.Area([(0, 0), (10, 9), (30, 8), (25, -11), (15, -12), (0, 0)]).opts(style=dict(color="lightgrey", line_color="white", line_dash=None, alpha=0.5)).redim.label(x="A (unitA)", y="B (unitB)")
接着:
%%opts Scatter [tools=[hover]] (size=10)
scatter * area
結果如下:
如果您將hv.Area
行替換為以下內容,
area = hv.Curve([(0, 0), (10, 90), (30, 80), (25, 110), (15, 120)]).opts(style=dict(line_color="black", line_dash="dashed", alpha=0.5))
您將看到軸及其標簽:
這是錯誤嗎? 還是我錯過了什么?
bokeh=0.12.7
holoviews=1.8.3
pandas=0.20.2
python=3.6.1
UPDATE
發表評論后,我將區域更改如下,
area = hv.Area([(0, 0), (10, 9), (30, 8), (25, -11), (15, -12), (0, 0)]).opts(style=dict(color="lightgrey", line_color="white", line_dash="solid", alpha=0.5)).redim.label(x="A (unitA)", y="B (unitB)")
但這有一條沿原點的丑陋線條作為副作用:
如果我做line_color="lightgrey"
並不會更好。
更新2
添加選項line_alpha=0
解決其中一項注釋中建議的問題。
area = hv.Area([(0, 0), (10, 9), (30, 8), (25, -11), (15, -12), (0, 0)]).opts(style=dict(color="lightgrey", line_color="white", line_dash="solid", alpha=0.5, line_alpha=0)).redim.label(x="A (unitA)", y="B (unitB)")
我不太確定這是怎么發生的或為什么發生的(我懷疑這是BokehJS中的問題),但似乎是line_dash=None
Area
元素的樣式選項中line_dash=None
,如果您刪除它或將其替換為line_dash='solid'
軸返回。
我會跟進,可能會在bokeh中提出問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.