A very useful Python library, particularly for creating interactive visualizations in web browsers, is `Bokeh`. Bokeh enables the building of complex statistical plots quickly and through simple commands. It's highly versatile, allowing for the creation of interactive plots, dashboards, and data applications with rich, web-based visualization capabilities. Below is a concise reference guide for common use cases with `Bokeh`, formatted in Markdown syntax: # `Bokeh` Reference Guide ## Installation ``` pip install bokeh ``` ## Basic Plotting ### Importing Bokeh ```python from bokeh.plotting import figure, show, output_file ``` ### Creating a Simple Line Plot ```python # Prepare some data x = [1, 2, 3, 4, 5] y = [6, 7, 2, 4, 5] # Output to static HTML file (opens in browser) output_file("lines.html") # Create a new plot with a title and axis labels p = figure(title="simple line example", x_axis_label='x', y_axis_label='y') # Add a line renderer with legend and line thickness p.line(x, y, legend_label="Temp.", line_width=2) # Show the results show(p) ``` ## Interactive Plots ### Adding Tools ```python from bokeh.models import PanTool, ResetTool, HoverTool # Adding pan, reset functionality p.add_tools(PanTool(), ResetTool()) # Adding hover tool hover = HoverTool() hover.tooltips=[ ("Index", "$index"), ("(x,y)", "($x, $y)"), ] p.add_tools(hover) ``` ### Widgets and Interactivity ```python from bokeh.layouts import column from bokeh.models import Slider, Button from bokeh.io import curdoc # Create some widgets slider = Slider(start=0, end=10, value=1, step=.1, title="Stuff") button = Button(label="Press me") # Update function def update(): # Update function for widgets ... # Button click event button.on_click(update) # Arrange widgets and plot into a layout layout = column(slider, button, p) # Add the layout to the current document curdoc().add_root(layout) ``` ## Embedding and Linking Plots ### Linking Plots Together ```python from bokeh.layouts import gridplot # Linking axes p1 = figure(width=250, height=250) p2 = figure(width=250, height=250, x_range=p1.x_range, y_range=p1.y_range) p3 = figure(width=250, height=250, x_range=p1.x_range) # Arrange plots in a grid grid = gridplot([[p1, p2], [None, p3]]) show(grid) ``` ### Embedding Bokeh Plots in HTML ```python from bokeh.embed import components script, div = components(p) # `script` is a