Python Bokeh:从图表中删除工具栏

33

维护者的注意事项:这个问题的具体内容涉及到已经过时并且在几年前就被移除的bokeh.charts API。在现代的Bokeh中,请使用toolbar_location进行指定:

p = figure(toolbar_location=None)

过时内容:

我似乎无法从bokeh Bar图表中删除工具栏。尽管将tools参数设置为None(或False''),但最终总是有bokeh的标志和一条灰线,例如使用以下代码:

from bokeh.charts import Bar, output_file, show

# prepare some data
data = {"y": [6, 7, 2, 4, 5], "z": [1, 5, 12, 4, 2]}

# output to static HTML file
output_file("bar.html")

# create a new line chat with a title and axis labels
p = Bar(data, cat=['C1', 'C2', 'C3', 'D1', 'D2'], title="Bar example",
                xlabel='categories', ylabel='values', width=400, height=400,
                tools=None)

# show the results
show(p)

然而,当我尝试使用一个bokeh plot时,它完美地工作,并且工具栏消失了,例如使用以下代码:

from bokeh.plotting import figure, output_file, show

output_file("line.html")

p = figure(plot_width=400, plot_height=400, toolbar_location=None)

# add a line renderer
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)

show(p)

有人知道我做错了什么吗?

2个回答

60

如果您想要移除标志和工具栏,您可以这样做:

p.toolbar.logo = None
p.toolbar_location = None
希望这能解决你的问题。

希望这能解决你的问题


如何从gridPlot中移除工具栏,从子图中移除无效,无法移除gridplot:AttributeError: 'Column'对象没有属性'toolbar'。 - user3598726
4
toolbar_location=None是gridplot函数的一个参数,用于指定网格图中的工具栏位置。 - Eoin

5

在任何Bokeh绘图对象上,您都可以设置:

p.toolbar_location = None

我也尝试过(在括号中提到_False_和_''_也不起作用)。但你是对的,根据指南它应该可以工作。不幸的是,它仍然给我标志和水平线... - Arkady
你正在使用哪个版本的 Bokeh? - Luke Canavan
bokeh.__version__ 给我的结果是 0.9.2 - Arkady
抱歉回复晚了 - 在你编辑答案后我没有收到邮件,还以为大家都忘了我的问题...你的答案是正确的,我可以像@Merqurio指出的那样用p.logo来去除标志。 - Arkady

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接