Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed bokeh plot in markdown

Tags:

python

plot

bokeh

I could not find any documentation on embedding bokeh plots in markdown styled documents. Is there an easy way to do this using the script and div tags that bokeh.embed.components ?

like image 790
ajkl Avatar asked Apr 19 '26 01:04

ajkl


1 Answers

If your Markdown flavour supports <embed> tags this is possible using the .html file generated by Bokeh's output_file().

In Python:

from bokeh.plotting import figure, output_file, show

p = figure(title="example", x_axis_label='x', y_axis_label='y')

output_file("example.html")
show(p)  # Needed to actually save the file

In Markdown:

<embed type="text/html" src="relative/path/to/example.html" width="600" height="400"></embed>

Note that the width and height attributes are necessary since it won't auto-size.

This method does have the minor drawback of needing to keep the plot files with the Markdown.

like image 120
Lif3line Avatar answered Apr 21 '26 16:04

Lif3line



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!