您的位置:宽带测速网 > 编程知识 > 如何将Bokeh图表导出为PNG或SVG格式

如何将Bokeh图表导出为PNG或SVG格式

2025-06-23 19:32来源:互联网 [ ]

要将Bokeh图表导出为PNG或SVG格式,可以使用Bokeh的导出功能。例如,可以使用以下代码将Bokeh图表导出为PNG格式:

from bokeh.io import export_pngfrom bokeh.plotting import figure# 创建Bokeh图表p = figure()p.circle([1, 2, 3], [4, 5, 6])# 将图表导出为PNG格式export_png(p, filename="plot.png")

要将Bokeh图表导出为SVG格式,可以使用以下代码:

from bokeh.io import export_svgsfrom bokeh.plotting import figure# 创建Bokeh图表p = figure()p.circle([1, 2, 3], [4, 5, 6])# 将图表导出为SVG格式export_svgs(p, filename="plot.svg")

这些代码将在当前目录下创建一个名为"plot.png"或"plot.svg"的文件,其中包含导出的图表。