Skip to main content

Observable Plot in Jupyter notebooks

Project description

pyobsplot

PyPI Tests Documentation

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

Sample plot screenshot

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:

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.
  • 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).

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

Uploaded Source

Built Distribution

pyobsplot-0.2.0-py3-none-any.whl (281.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyobsplot-0.2.0.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

Hashes for pyobsplot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2ab61f908eb4fce923c65d9a406b98ae7802f72878f2ab247af3b4b8fd563735
MD5 00b0cd0b879346605a67aa29a14a325a
BLAKE2b-256 4d2c72ff57875a4df9d7670f714f49cb159167b7a225e3cbd8013e34c0a698a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyobsplot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 281.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e426f8af8fffd2f495d4aaf9102ff998c350e188077743ebcb3be60277cf5b43
MD5 c1ce9be547240a6344760dec30cca9d9
BLAKE2b-256 6afc6578e4bcf4cb08294d2b329fec5936ecdb4847d33ec310bc3b8b328530cf

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