目标是在 google colab 中保存带散景的 svg-figure。
的文档结果:运行时错误,s。详情如下
p = bokeh.plotting.figure(
width=400,
height=300,
x_axis_label="confidence when correct",
y_axis_label="confidence when incorrect",
)
p.circle(
source=df,
x="confidence when correct",
y="confidence when incorrect"
)
p.output_backend = "svg"
bokeh.io.export_svgs(p, filename="insomniac_confidence_correct.svg")
Then there is an error:
RuntimeError: To use bokeh.io image export functions you need selenium ('conda install selenium' or 'pip install selenium')
使用 Colab 中的 Bokeh 导出到 SVG 的示例代码:
!pip install bokeh
!pip install google-colab-selenium
from bokeh.plotting import figure as Figure
from bokeh.io import export_svg
from google_colab_selenium import Chrome
example_figure = Figure()
example_figure.line(x=[0, 1, 2], y=[3, 5, 4])
webdriver = Chrome()
example_figure.output_backend = 'svg'
export_svg(example_figure, filename='example_figure.svg', webdriver=webdriver)
Bokeh 期望可以使用网络浏览器来创建其图形。对于运行 Colab 实例的虚拟机的设置方式来说,这可能有点棘手。您可以在虚拟机实例上手动安装正确的浏览器软件包。或者,您可以使用类似
google-colab-selenium
包的东西来为您完成安装工作。