Observable Plot in Jupyter notebooks and Quarto documents
pyobsplot
allows to use Observable Plot to create charts in Jupyter notebooks, VSCode notebooks, Google Colab and Quarto documents. Plots are created from Python code with a syntax as close as possible to the JavaScript one.
It allows to do things like :
import polars as pl
from pyobsplot import Plot
penguins = pl.read_csv("https://github.com/juba/pyobsplot/raw/main/doc/data/penguins.csv")
Plot.plot({
"grid": True,
"color": {"legend": True},
"marks": [
Plot.dot(
penguins,
{"x": "flipper_length_mm", "y": "body_mass_g", "fill": "species"}
),
Plot.density(
penguins,
{"x": "flipper_length_mm", "y": "body_mass_g", "stroke": "species"}
)
]
})
pyobsplot
can be installed with pip
:
pip install pyobsplot
For usage instructions, see the documentation website:
If you just want to try this package without installing it on your computer, you can open an introduction notebook in Google Colab:
Features:
widget
, which generates plots as Jupyter widgets, and jsdom
, which generates SVG or HTML outputsjs
methoddate
and datetime
objects are automatically converted to JavaScript Date
objectsjsdom
renderer.Limitations:
jsdom
renderer (https://github.com/juba/pyobsplot/issues/16).jsdom
renderer has been adapted from altair_saver.