--- # Posts need to have the `post` layout layout: post # The title of your post title: "Embedding Bokeh plots with Github Pages" # (Optional) Write a short (~150 characters) description of each blog post. # This description is used to preview the page on search engines, social media, etc. description: > A quick how-to guide for embedding interactive Javascript plots, made with the Bokeh library in Python, on a Github Pages site. # (Optional) Link to an image that represents your blog post. # The aspect ratio should be ~16:9. #image: /assets/img/insta.jpg # You can hide the description and/or image from the output # (only visible to search engines) by setting: # hide_description: true # hide_image: true categories: [misc] tags: [how-to] languages: [Python] --- ![](/assets/img/Bokeh/header.PNG){:.lead} From bokeh.pydata.org: > Bokeh is a Python interactive visualization library that targets modern web browsers for presentation. Its goal is to provide elegant, concise construction of novel graphics in the style of D3.js, and to extend this capability with high-performance interactivity over very large or streaming datasets. Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.
This is a quick guide to embedding your visualizations in a Jekyll-hosted site, such as a Github Pages blog. * dummy list {:toc} # Method 1: Embedding a single plot at a time with output_file() By far the simplest option is to use the `output_file()` function to produce a single HTML document. For this demo, I'll use a slightly modified version of a classic example in the Bokeh documentation, [Iris.py](https://bokeh.pydata.org/en/latest/docs/gallery/iris.html). ```python import pandas as pd from bokeh.sampledata.iris import flowers from bokeh.plotting import figure, show, output_file from bokeh.models import ColumnDataSource, HoverTool colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'} flowers['colors'] = [colormap[x] for x in flowers['species']] hover = HoverTool(tooltips=[ ("Sepal length", "@sepal_length"), ("Sepal width", "@sepal_width"), ("Petal length", "@petal_length"), ("Species", "@species") ]) p = figure(title = "Iris Morphology", plot_height=500, plot_width=500, tools=[hover, "pan,reset,wheel_zoom"]) p.xaxis.axis_label = 'Petal Length' p.yaxis.axis_label = 'Petal Width' p.circle('petal_length', 'petal_width', color='colors', fill_alpha=0.2, size=10, source=ColumnDataSource(flowers)) output_file('flowers.html') show(p) ``` This command produces a single HTML file. Save this file to your github pages directory. Looking at the root directory, mine will go: ``` +-- assets --img --Bokeh --flowers.html ``` Finally, inline in your markdown file, insert an `` tag, like the example below: ```html ``` When you serve the website locally using Jekyll or post to Github Pages, your plot should be nicely embedded, interactive elements and all, as seen below: This system works with embedding multiple files in different locations on your page, simply include a `