Skip to main content

Altair extension for saving charts to various formats.

Project description

Altair Saver

github actions github actions code style black Open in Colab

This packge provides extensions to Altair for saving charts to a variety of output types. Supported output formats are:

  • .json/.vl.json: Vega-Lite JSON specification
  • .vg.json: Vega JSON specification
  • .html: HTML output
  • .png: PNG image
  • .svg: SVG image
  • .pdf: PDF image

Usage

The altair_saver library has a single public function, altair_saver.save(). Given an Altair chart named chart, you can use it as follows:

from altair_saver import save

save(chart, "chart.vl.json")              # Vega-Lite JSON specification
save(chart, "chart.vg.json")              # Vega JSON specification
save(chart, "chart.html")                 # HTML document
save(chart, "chart.html", inline=True)    # HTML document with all JS code included inline
save(chart, "chart.png")                  # PNG Image
save(chart, "chart.svg")                  # SVG Image
save(chart, "chart.pdf")                  # PDF Image

Renderer

Additionally, altair_saver provides an Altair Renderer entrypoint that can display the above outputs directly in Jupyter notebooks. For example, you can specify a vega-lite mimetype (supported by JupyterLab, nteract, and other platforms) with a PNG fallback for other frontends as follows:

alt.renderers.enable('altair_saver', ['vega-lite', 'png'])

Installation

The altair_saver package can be installed with:

$ pip install altair_saver

Saving as vl.json and as html requires no additional setup.

To install with conda, use

$ conda install -c conda-forge altair_saver

The conda package installs the NodeJS dependencies described below, so charts can be saved to png, svg, and pdf without additional setup.

Additional Requirements

Output to png, svg, and pdf requires execution of Javascript code, which altair_saver can do via one of two backends.

Selenium

The selenium backend supports the following formats:

  • .vg.json
  • .png
  • .svg.

To be used, it requires the Selenium Python package, and a properly configured installation of either chromedriver or geckodriver.

On Linux systems, this can be setup as follows:

$ pip install selenium
$ apt-get install chromium-chromedriver

Using conda, the required packages can be installed as follows (a compatible version of Google Chrome must be installed separately):

$ conda install -c python-chromedriver-binary

Selenium supports other browsers as well, but altair-saver is currently only tested with Chrome.

NodeJS

The nodejs backend supports the following formats:

  • .vg.json
  • .png
  • .svg
  • .pdf

It requires NodeJS, along with the vega-lite, vega-cli, and canvas packages.

First install NodeJS either by direct download or via a package manager, and then use the npm tool to install the required packages:

$ npm install vega-lite vega-cli canvas

Using conda, node and the required packages can be installed as follows:

$ conda install -c conda-forge vega-cli vega-lite-cli

These packages are included automatically when installing altair_saver via conda-forge.

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

altair_saver-0.4.0.tar.gz (83.4 kB view details)

Uploaded Source

Built Distribution

altair_saver-0.4.0-py3-none-any.whl (87.4 kB view details)

Uploaded Python 3

File details

Details for the file altair_saver-0.4.0.tar.gz.

File metadata

  • Download URL: altair_saver-0.4.0.tar.gz
  • Upload date:
  • Size: 83.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

File hashes

Hashes for altair_saver-0.4.0.tar.gz
Algorithm Hash digest
SHA256 20a9ed979155e777b7ff63963f3ccad69ef6c4b91e014fcd9c0a3ed2e42b46e0
MD5 9e2c8534b627c27a62b66a989d8760af
BLAKE2b-256 9de07eebb629a575e47bbef158653b7981b36fad07a950ee6402a60ff63f23b4

See more details on using hashes here.

Provenance

File details

Details for the file altair_saver-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: altair_saver-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 87.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.5

File hashes

Hashes for altair_saver-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f170a9d51d176b7d3fd17e12c63189e4067788a622530906e672cde0cf63616f
MD5 8beb6008303397cb2f4c900f6f8a2a44
BLAKE2b-256 78f1aede783ed0730c9eba578bd7ae8ddb5e9c7c2d744f2ca24de12e32997519

See more details on using hashes here.

Provenance

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