Saving html file with images in bokeh

后端 未结 2 1700
生来不讨喜
生来不讨喜 2021-02-04 21:08

I\'m creating a bokeh plot containing several images. I create and show my file like this:

output_file(my_dir + \"Graphs\\\\graph\")
show(bar)

2条回答
  •  滥情空心
    2021-02-04 21:28

    As the documentation mentions, you have two ways to achieve this:

    • using save() instead of show()

      from bokeh.plotting import figure, output_file, save
      p = figure(title="Basic Title", plot_width=300, plot_height=300)
      p.circle([1, 2], [3, 4])
      output_file("test.html")
      save(p)
      
    • using the file_html function, which is low-level

      from bokeh.plotting import figure
      from bokeh.resources import CDN
      from bokeh.embed import file_html
      
      plot = figure()
      plot.circle([1,2], [3,4])
      
      html = file_html(plot, CDN, "my plot")
      
      with open("/myPath.html") as f:
          f.write(html)
      

提交回复
热议问题