【发布时间】:2018-07-04 23:47:44
【问题描述】:
我对散景很陌生。我试图在我的一个图上添加可点击的链接,更准确地说是在 x 轴上(在刻度上)。
我的问题:是否可以在刻度标签中使用 HTML 代码,例如用超文本链接替换文本?
以 Bokeh 文档中的一个示例为例,这是我的幼稚尝试(替换其中一个标签,从 Apples 到 <a>Apples</a>):
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral6
from bokeh.plotting import figure
output_file("bar_colors.html")
fruits = ['<a>Apples</a>', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
source = ColumnDataSource(data=dict(fruits=fruits, counts=counts, color=Spectral6))
p = figure(x_range=fruits, y_range=(0,9), plot_height=350, title="Fruit Counts",
toolbar_location=None, tools="")
p.vbar(x='fruits', top='counts', width=0.9, color='color', legend="fruits", source=source)
p.xgrid.grid_line_color = None
p.legend.orientation = "horizontal"
p.legend.location = "top_center"
show(p)
正如您可能已经猜到的那样,它会导致我将<a>Apples</a> 写成文本...
我应该如何获得正确的超文本链接?
【问题讨论】: