Observable Plot in Jupyter notebooks
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
Warning: this project is at a very early stage. There will be bugs, and please take a look at the limitations listed below.
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
- Two renderers available:
widget
, which generates plots as Jupyter widgets, andjsdom
, which generate SVG or HTML outputs - 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 - Works with Jupyter notebooks and Quarto HTML documents. Plots without legends are also supported in PDF and docx outputs with the
jsdom
renderer.
Limitations:
- Plots with legends don't work in Quarto in formats other than HTML.
- Some faceting operations produce warnings when used as top-level faceting (but the plots should be fine). This doesn't happen when using mark-level faceting (with the
fx
andfy
channels).
Credits
- Observable Plot, developed by Mike Bostock and Philippe Rivière among others.
- The widget is developed thanks to the anywidget framework.
- Some code from the
jsdom
renderer has been adapted from altair_saver. - The 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.2.1.tar.gz
(279.3 kB
view details)
Built Distribution
pyobsplot-0.2.1-py3-none-any.whl
(281.6 kB
view details)
File details
Details for the file pyobsplot-0.2.1.tar.gz
.
File metadata
- Download URL: pyobsplot-0.2.1.tar.gz
- Upload date:
- Size: 279.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb97f891e051c8f72d98ddf8906c02849141544ecfe0966d56fb509e2e29a620 |
|
MD5 | 37a1729ccea0a5e42171ac05eae10fe5 |
|
BLAKE2b-256 | 02c077234d2b2e8c90f590cfe689df76f5db2484eb35cace5cb29caa3c37320b |
File details
Details for the file pyobsplot-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pyobsplot-0.2.1-py3-none-any.whl
- Upload date:
- Size: 281.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15ef887e056ee2af5b5133c9c9bfb42013d015123278c476e4d5b2599afdc6a3 |
|
MD5 | dd726f084b1645c4cda575ff6603ade2 |
|
BLAKE2b-256 | 5624bcde3fa46f8fa8c02f167d4771ca57036e10370e0f97438c0688f228051e |