Skip to main content

Observable Plot in Jupyter notebooks and Quarto documents

Project description

pyobsplot

PyPI Tests Documentation Open In Colab

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"}
        )
    ]
})

Sample plot screenshot

Installation and usage

Warning: this project is at an early stage. There will be bugs, and the API may change.

pyobsplot can be installed with pip:

pip install pyobsplot

For usage instructions, see the documentation website:

Features and limitations

Features:

  • Syntax as close as possible to the JavaScript one
  • Two renderers available: widget, which generates plots as Jupyter widgets, and jsdom, 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 and datetime objects are automatically converted to JavaScript Date 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. (#9)
  • 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 and fy channels). (#3)

Credits

Project details


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.3.1.tar.gz (481.8 kB view details)

Uploaded Source

Built Distribution

pyobsplot-0.3.1-py3-none-any.whl (485.9 kB view details)

Uploaded Python 3

File details

Details for the file pyobsplot-0.3.1.tar.gz.

File metadata

  • Download URL: pyobsplot-0.3.1.tar.gz
  • Upload date:
  • Size: 481.8 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

Hashes for pyobsplot-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7b7c607142a33ba9f171a532e761503f09cefe934d8849853f5e9b8f7835a658
MD5 4ecacff4cc24f1c799cc04d078ccb516
BLAKE2b-256 1367b7627727955b59a3460114ef745ade1a7d6c9412aeea2c7bbd5c9a90d1c7

See more details on using hashes here.

File details

Details for the file pyobsplot-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pyobsplot-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 485.9 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

Hashes for pyobsplot-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a631e3e4fddf45c115aa959440527c517ecde4dc2202fca2d3306269282925e
MD5 d21d2d0fb617ab5291c514439b1c2d9c
BLAKE2b-256 58f201cfd56b23c656773dba4d950ac3eda6e40311c20da9b6601b9ad9c7beb6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page