pyobsplot
pyobsplot copied to clipboard
Added typst renderer to support png/pdf/jpg/svg exports
This is a pull request addressing https://github.com/juba/pyobsplot/issues/23
Supported output formats are
- png
- svg (including title, caption etc)
Example
from pyobsplot import Obsplot, Plot
import polars as pl
penguins = pl.read_csv("https://github.com/juba/pyobsplot/raw/main/doc/data/penguins.csv")
op = Obsplot(renderer="typst", dpi=300, font="SF Pro Display", font_size=14, margin=4)
op({
"color": {"legend": True},
"marginLeft": 80,
"marginRight": 80,
"title": "Penguin body mass by island",
"x": {"inset": 20},
"grid": True,
"marks": [
Plot.boxX(penguins, {
"x": "body_mass_g", "fill": "island", "y": "island", "fy": "species"
})
]
})
results in
Writing to file
op(spec, path="file.png")
saves the output to a file
Issues
- One minor issue is that some font needs to be installed on the system supporting glyphs like → (RIGHTWARDS ARROW', U+2192). I am using SF Pro Display which is free.
- I am not sure how to handle options. For my taste a global option like
op = Obsplot(renderer="typst", dpi=300, font="SF Pro Display", font_size=14, margin=4)
over something like
op(spec, path="file.png", dpi=300, font="SF Pro Display", font_size=14, margin=4)