Observable Plot as Jupyter widget
Project description
pyobsplot
pyobsplot
allows to use Observable Plot to create charts in Jupyter notebooks. Plots are produced as widgets 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 Obsplot, Plot
penguins = pl.read_csv("data/penguins.csv")
Obsplot({
"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"}
)
]
})
Installation and usage
pyobsplot
can be installed with pip
:
pip install pyobsplot
For usage instructions, see the documentation website:
- See getting started for a quick usage overview.
- See usage for more detailed usage instructions.
Features and limitations
Features:
- Syntax as close as possible to the JavaScript one
- Pandas and polars DataFrame and Series objects are serialized using Arrow IPC format for improved speed and data type conversions
- Works offline, no iframe or dependency to Observable runtime
- Caching mechanism of data objects if they are used several times in the same plot
- Custom JavaScript code can be passed as strings with the
js
method - Python
date
anddatetime
objects are automatically converted to JavaScriptDate
objects - Plots can be defined with a dictionary, a call to a
Plot
mark function, or withkwargs
. See alternative syntaxes. - Works with Jupyter notebooks and Quarto HTML documents
Limitations:
- When using notebooks inside VSCode, the cells output states are not saved between sessions. So when a notebook is closed and reopened, plots have to be recomputed to be displayed. This is currently a VSCode limitation.
- Doesn't work in Quarto in formats other than HTML.
Credits
- Observable Plot, developed by Mike Bostock and Philippe Rivière among others.
- The widget is developed thanks to the anywidget framework.
- This documentation website is generated by Quarto and the bookup custom format.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyobsplot-0.1.0.tar.gz
(275.8 kB
view hashes)
Built Distribution
pyobsplot-0.1.0-py3-none-any.whl
(277.4 kB
view hashes)
Close
Hashes for pyobsplot-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99b2b8333397ddbc6e24b3a67cf78cf3f2ad2f6cdf2d1a41d152a78b983f29c1 |
|
MD5 | 298808934d25e9a788fca9a01834211c |
|
BLAKE2b-256 | ad22e11e33e2360e788d762c07bd2c1e363cea7d76a9afc022a4bb05e16f2b3e |