Vega-Altair: A declarative statistical visualization library for Python

6.0.0 · active · verified Sat Mar 28

Altair is a declarative statistical visualization library for Python, built on top of the powerful Vega-Lite JSON specification. It offers a simple, friendly, and consistent API for creating a wide range of interactive and aesthetically pleasing statistical charts with a minimal amount of code. The library is actively developed, with a current stable version of 6.0.0 and weekly pre-release builds.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic bar chart using Altair with a pandas DataFrame. It defines a DataFrame, then uses `alt.Chart()` to specify the data, `mark_bar()` to choose the chart type, and `encode()` to map data columns to visual properties (x and y axes). The `.show()` method attempts to render the chart in a compatible environment.

import altair as alt
import pandas as pd

# Sample data
data = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

# Create a simple bar chart
chart = alt.Chart(data).mark_bar().encode(
    x='a',
    y='b'
)

chart.show()

view raw JSON →