Jupyter widgets enable interactive data visualization in the Jupyter notebooks.
Notebooks come alive when interactive widgets are used. Users can visualize and control changes in the data. Learning becomes an immersive, plus fun, experience. Researchers can easily see how changing inputs to a model impacts the results.
A library for creating simple interactive maps with panning and zooming, ipyleaflet supports annotations such as polygons, markers, and more generally any geojson-encoded geographical data structure.
from ipyleaflet import Map
Map(center=[34.6252978589571, -77.34580993652344], zoom=10)
conda install -c conda-forge ipyleaflet
pip install ipyleaflet
jupyter nbextension enable --py --sys-prefix ipyleaflet
A Jupyter widget to interactively view molecular structures and trajectories.
import pytraj as pt
import nglview as nv
traj = pt.load('sim.nc', top='sim.prmtop')
traj.strip(":TIP3")
view = nv.show_pytraj(traj)
view.clear()
view.add_cartoon('protein', color_scheme='residueindex')
view.add_ball_and_stick('not protein', opacity=0.5)
view
conda install -c bioconda nglview
pip install nglview
jupyter nbextension enable --py --sys-prefix nglview
A 2-D interactive data visualization library implementing the constructs of the grammar of graphics, bqplot provides a simple API for creating custom user interactions.
import numpy as np
import bqplot.pyplot as plt
size = 100
plt.figure(title='Scatter plot with colors')
plt.scatter(np.random.randn(size), np.random.randn(size), color=np.random.randn(size))
plt.show()
conda install -c conda-forge bqplot
pip install bqplot
jupyter nbextension enable --py --sys-prefix bqplot
A 3-D visualization library enabling GPU-accelerated computer graphics in Jupyter.
from pythreejs import *
f = """
function f(origu,origv) {
// scale u and v to the ranges I want: [0, 2*pi]
var u = 2*Math.PI*origu;
var v = 2*Math.PI*origv;
var x = Math.sin(u);
var y = Math.cos(v);
var z = Math.cos(u+v);
return new THREE.Vector3(x,y,z);
}
"""
surf_g = ParametricGeometry(func=f, slices=16, stacks=16)
surf = Mesh(geometry=surf_g, material=MeshLambertMaterial(color='green', side='FrontSide'))
surf2 = Mesh(geometry=surf_g, material=MeshLambertMaterial(color='yellow', side='BackSide'))
c = PerspectiveCamera(position=[5, 5, 3], up=[0, 0, 1],
children=[DirectionalLight(color='white',
position=[3, 5, 1],
intensity=0.6)])
scene = Scene(children=[surf, surf2, c, AmbientLight(intensity=0.5)])
Renderer(camera=c, scene=scene, controls=[OrbitControls(controlling=c)], width=400, height=400)
conda install -c conda-forge pythreejs
pip install pythreejs
jupyter nbextension enable --py --sys-prefix pythreejs
3-D plotting for Python in the Jupyter notebook based on IPython widgets using WebGL.
import ipyvolume.pylab as p3
import numpy as np
fig = p3.figure()
q = p3.quiver(*stream.data[:,0:50,:200], color="red", size=7)
p3.style.use("dark") # looks better
p3.animation_control(q, interval=200)
p3.show()
conda install -c conda-forge ipyvolume
pip install ipyvolume
jupyter nbextension enable --py --sys-prefix ipyvolume
BeakerX includes widgets for interactive tables, plots, forms, Apache Spark, and more. The table widget automatically recognizes pandas dataframes and allows you to search, sort, drag, filter, format, select, graph, hide, pin, and export to CSV or clipboard. This makes connecting to spreadsheets quick and easy.
The table widget, shown below, is so fast because it's implemented with the PhosphorJS Data Grid, part of Jupyter Lab's architecture.
import pandas as pd
from beakerx import *
pd.read_csv("UScity.csv")
conda install -c conda-forge beakerx ipywidgets
pip install beakerx
beakerx-install
Gmaps lets you embed interactive Google maps in Jupyter notebooks. Visualize your data with heatmaps, GeoJSON, symbols and markers, or plot directions, traffic, or cycle routes. Let users draw on the map and capture the coordinates of the markers or polygons they are placing to build interactive applications entirely in Python.
import gmaps
import gmaps.datasets
gmaps.configure(api_key="AI...") # Your Google API key
locations = gmaps.datasets.load_dataset("taxi_rides")
fig = gmaps.figure()
# locations could be an array, a dataframe or just a Python iterable
fig.add_layer(gmaps.heatmap_layer(locations))
fig
conda install -c conda-forge gmaps
pip install gmaps
jupyter nbextension enable --py --sys-prefix gmaps
The Jupyter widget framework is extensible and enables developers to create custom widget libraries and bindings for visualization libraries of the JavaScript ecosystem.
The cookiecutter
project helps widget authors get up to speed with the
packaging and distribution of Jupyter interactive widgets.
It produces a base project for a Jupyter interactive widget library following the current best practices. An implementation for a placeholder "Hello World" widget is provided. Following these practices will help make your custom widgets work in static web pages (like the examples of this page) and be compatible with future versions of Jupyter.