Declarative Visualization in Python¶
Altair is a declarative statistical visualization library for Python, based on Vega-Lite.
With Altair, you can spend more time understanding your data and its meaning. Altair’s API is simple, friendly and consistent and built on top of the powerful Vega-Lite visualization grammar. This elegant simplicity produces beautiful and effective visualizations with a minimal amount of code.
Note: Altair and the underlying Vega-Lite library are under active development, and the documentation here, although extensive, remains incomplete. We are currently (October 2017) working on support for Vega-Lite 2.0, and plan to significantly expand the documentation once that is released.
Here is an example of using the Altair API to quickly visualize a dataset:
import altair as alt # load built-in dataset as a pandas DataFrame cars = alt.load_dataset('cars') # Uncomment for rendering in JupyterLab & nteract # alt.enable_mime_rendering() alt.Chart(cars).mark_circle().encode( x='Horsepower', y='Miles_per_Gallon', color='Origin', )
The key idea is that you are declaring links between data columns and visual encoding channels, such as the x-axis, y-axis, color, etc. The rest of the plot details are handled automatically. Building on this declarative plotting idea, a surprising number of useful plots and visualizations can be created and a relatively small grammar.
- Narrative Documentation
- API Reference
- Example Gallery
- Plot Recipes
- Frequently Asked Questions
- Does Altair work in more modern frontends such as JupyterLab or nteract
- Why isn’t my plot displaying in the Jupyter Notebook?
- Why do Altair plots lead to such extremely large notebooks?
- How do I make a heatmap / violin plot / histogram / regression plot?
- How can I configure the tick marks / labels / size / appearance of my plot?
- How can I add marks to my line plot?