Observable Plot in Jupyter notebooks and Quarto documents
Project description
pyobsplot
pyobsplot allows to use Observable Plot to create charts in Jupyter or Marimo notebooks 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[typst]
To use pyobsplot in JupyterLite or marimo you must install it without the typst dependency, which is not yet compatible with pyodide:
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, JupyterLite and Marimo notebooks as well as in 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
jsmethod - Python
dateanddatetimeobjects are automatically converted to JavaScriptDateobjects
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
jsdomrenderer 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyobsplot-0.5.4.tar.gz.
File metadata
- Download URL: pyobsplot-0.5.4.tar.gz
- Upload date:
- Size: 485.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
752ef55bc949ecfe32a4d20b9bfb95185bb7abe49b257f370fa0f3a922c6b486
|
|
| MD5 |
fe2856e99cc15a47eeebbe47d4ac6fc8
|
|
| BLAKE2b-256 |
0fe1913e7f6248d3250e81c6c024775d4569094fde034e36194699262c360e94
|
File details
Details for the file pyobsplot-0.5.4-py3-none-any.whl.
File metadata
- Download URL: pyobsplot-0.5.4-py3-none-any.whl
- Upload date:
- Size: 313.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe3b5a0c2a0b0bec49c50448046eb73d98f19c42eb6d95206f46a27ceb95e6be
|
|
| MD5 |
f2efdddb054f44d83463bb943b68e28f
|
|
| BLAKE2b-256 |
39cdbfdb0639ec428c87f25e339a9d3cf844b5f67195bfbad1c8b4b5b17a9a22
|