Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/juba/pyobsplot
Observable Plot in Jupyter notebooks and Quarto documents
https://github.com/juba/pyobsplot
anywidget jupyter jupyter-widget observable-plot python quarto
Last synced: 2 days ago
JSON representation
Observable Plot in Jupyter notebooks and Quarto documents
- Host: GitHub
- URL: https://github.com/juba/pyobsplot
- Owner: juba
- License: mit
- Created: 2023-03-29T08:38:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-12T21:18:53.000Z (5 months ago)
- Last Synced: 2025-01-27T14:37:45.544Z (8 days ago)
- Topics: anywidget, jupyter, jupyter-widget, observable-plot, python, quarto
- Language: HTML
- Homepage: https://juba.github.io/pyobsplot/
- Size: 107 MB
- Stars: 214
- Watchers: 6
- Forks: 7
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
# pyobsplot
[![PyPI](https://img.shields.io/pypi/v/pyobsplot.svg?color=green)](https://pypi.org/project/pyobsplot)
[![npm](https://img.shields.io/npm/v/pyobsplot?color=green)](https://www.npmjs.com/package/pyobsplot)
[![Tests](https://github.com/juba/pyobsplot/actions/workflows/tests.yml/badge.svg)](https://github.com/juba/pyobsplot/actions/workflows/tests.yml)
[![Documentation](https://github.com/juba/pyobsplot/actions/workflows/publish.yml/badge.svg)](https://github.com/juba/pyobsplot/actions/workflows/publish.yml)
[![Open In Colab](https://github.com/juba/pyobsplot/raw/main/doc/img/colab-badge.svg)](https://colab.research.google.com/github/juba/pyobsplot/blob/main/examples/introduction.ipynb)`pyobsplot` allows to use [Observable Plot](https://observablehq.com/@observablehq/plot?collection=@observablehq/plot) to create charts in [Jupyter](https://jupyter.org) notebooks, [VSCode](https://code.visualstudio.com) notebooks, [Google Colab](https://colab.research.google.com) and [Quarto](https://quarto.org) documents. Plots are created from Python code with a syntax as close as possible to the JavaScript one.
It allows to do things like :
```python
import polars as pl
from pyobsplot import Plotpenguins = 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](https://github.com/juba/pyobsplot/raw/main/doc/screenshots/readme_plot.png)
## Installation and usage
`pyobsplot` can be installed with `pip`:
```sh
pip install pyobsplot
```For usage instructions, see the [documentation website](https://juba.github.io/pyobsplot):
- See [getting started](https://juba.github.io/pyobsplot/getting_started.html) for a quick usage overview.
- See [usage](https://juba.github.io/pyobsplot/usage.html) 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:
[![](https://github.com/juba/pyobsplot/raw/main/doc/img/colab-badge.svg)](https://colab.research.google.com/github/juba/pyobsplot/blob/main/examples/introduction.ipynb)
## 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](https://pandas.pydata.org) and [polars](https://pola.rs) DataFrame and Series objects are serialized using [Arrow](https://arrow.apache.org) 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` and `datetime` objects are automatically converted to JavaScript `Date` objects**Limitations:**
- Plot interactions (tooltips, crosshair...) are only available with the "widget" format ().
- Very limited integration with IDE (documentation and autocompletion) for Plot methods. ()## Credits
- [Observable Plot](https://observablehq.com/@observablehq/plot?collection=@observablehq/plot), developed by [Mike Bostock](https://observablehq.com/@mbostock) and [Philippe Rivière](https://observablehq.com/@fil) among others.
- The widget is developed thanks to the [anywidget](https://anywidget.dev) framework.
- [typst](https://typst.app) is used to convert HTML figures to PNG, SVG or PDF.
- Some code from the `jsdom` renderer has been adapted from [altair_saver](https://github.com/altair-viz/altair_saver).
- The documentation website is generated by [Quarto](https://quarto.org).