Skip to content

HoloViews and Bokeh

BK Jackson edited this page Feb 27, 2020 · 6 revisions

Panel

JavaScript command jslink to link widgets and plots in Panel

temp_alpha_slider = pn.widgets.FloatSlider(start=0, end=1, value=.5, name='Temperature alpha')
temp_alpha_slider.jslink(temp_p, value='glyph.global_alpha')

Serve Panel dashboard in Jupyter notebook

dashboard.servable()  

Save Panel Dashboard to HTML with or without Python kernel

Without Python kernel

dashboard.save('heat_and_trees.html')

Python kernel OR embedded output (e.g., for geopandas tile selector)

dashboard.save('heat_and_trees_embedded.html', title='Heat and Trees', embed=True)  

HoloViews

Data Visualization with Python HoloViz: Interactive Plots and Widgets in Jupyter - Blog by Ernest Kim, Aug 25, 2019
Data Visualization with the HoloViews Suite: holoviz_extended - related repo, useful machine learning examples and examples of writing visualization class and methods with HoloViz. Also, numba optimized functions with @nb.njit.
Customizing Axes, Legends, Colorbars, etc.

Official Bokeh Pages

Bokeh Home
Bokeh User Guide
Bokeh Tutorials
Bokeh Gallery
Styling Visual Attributes - line properties, etc.

Bokeh Interactivity

Layouts, Widgets, and Interactions Tutorial

Bokeh Examples

Create shaded plot with datetime X-axis (notebook version)

from bokeh.plotting import figure, output_notebook, show  
import pandas as pd  

# For use in a jupyter notebook  
output_notebook()  

# Get AAPL stock timeseries data
aapl = pd.read_csv("aapl.csv")
aapl['Date'] = pd.to_datetime(aapl['Date'])
X_time = aapl['Date'] 
Y_val = aapl['Close']

# Use matplotlib to create colormap from data
import matplotlib.colors, matplotlib.cm

# Scale data from min to max values into interval [0,1] for use in ScalarMappable
norm = matplotlib.colors.Normalize(vmin=min(Y_val), vmax=max(Y_val))

# Map normalized values to RGBA
Y_rgba = matplotlib.cm.ScalarMappable(norm=norm, cmap='Spectral_r').to_rgba(Y_val)
colors = ["#%02x%02x%02x" % (int(r), int(g), int(b))
          for r, g, b, _ in 255*Y_rgba]

# Create a plot with a datetime axis type
p = figure(plot_width=700, plot_height=300, x_axis_type="datetime")

# Use vbar to create vertical "shading"
p.vbar(x=X_time, width=0.1, bottom=0, top=200, color=colors)

# Overlay timeseries over shaded bar plot
p.line(X_time, Y_val, color='navy', alpha=0.5)
show(p)

bokeh_shadedtimeseries

Other Bokeh articles and tutorials

Heat & Trees Example of Using Panel, HoloViz, Dask, and more (Github) - Visualizing and Analyzing Earth Science Data Using HoloViz and PyData, Earth Science presents interesting issues of large, multi-dimensional datasets stored in a variety of idiosyncratic file formats. In this talk, we'll work through some specific workflows and explore how various tools - such as intake, dask, xarray, and datashader - can be used to effectively analyze and visualize these data. Working from within the notebook, we'll iteratively build a product that is interactive, scalable and deployable. Nov 1, 2019

HoloViz

Data Visualization with Python HoloViz: Plotting - Ernest Kim, Aug 25, 2019

Clone this wiki locally