Observable Plot in Jupyter notebooks and Quarto documents
Project description
pyobsplot
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"}
)
]
})
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.
If you just want to try this package without installing it on your computer, you can open an introduction notebook in Google Colab:
Features and limitations
Features:
- Syntax as close as possible to the JavaScript one
- Plots can be generated as Jupyter widgets, or as SVG, HTML or PNG outputs (via typst)
- Plots can be saved to Widget HTML, static HTML, SVG, PNG or PDF files
- Pandas and polars DataFrame and Series objects are serialized using Arrow IPC format for improved speed and better data type conversions
- Works with Jupyter notebooks and Quarto documents
- 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
Limitations:
- Plot interactions (tooltips, crosshair...) are only available with the "widget" format (https://github.com/juba/pyobsplot/issues/16).
- Very limited integration with IDE (documentation and autocompletion) for Plot methods. (https://github.com/juba/pyobsplot/issues/13)
Credits
- Observable Plot, developed by Mike Bostock and Philippe Rivière among others.
- The widget is developed thanks to the anywidget framework.
- typst is used to convert HTML figures to PNG, SVG or PDF.
- Some code from the
jsdom
renderer has been adapted from altair_saver. - The documentation website is generated by Quarto.
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
Built Distribution
File details
Details for the file pyobsplot-0.5.1.tar.gz
.
File metadata
- Download URL: pyobsplot-0.5.1.tar.gz
- Upload date:
- Size: 450.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7724314dba8eba245e0c4446321ec9527a961b79ffbb9c35b797a0b0b42bf63 |
|
MD5 | 82292cb435649f565147e625db51e4d3 |
|
BLAKE2b-256 | 599e43528e1907e895c29418fb5d750f7d745a954b223325de293ab56eaad57d |
File details
Details for the file pyobsplot-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: pyobsplot-0.5.1-py3-none-any.whl
- Upload date:
- Size: 313.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a21a7553ae53aeaa9e541660ebd1e8a2f408d6f255c2a32ac6ca81f6d24eaeb |
|
MD5 | 88f9a615fc3ef09ba87c9650c8962fb9 |
|
BLAKE2b-256 | 1779db440ceef4fd1d63e083da560a2bac17945bd064a9920a65c38d30944f0f |