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.
pip install altairVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to 3.9 or higher. Review `pyproject.toml` or `setup.cfg` for `requires_python` constraints.
Consult the Vega-Lite 6 release notes for any specific breaking changes relevant to your custom specifications. Test existing complex charts after upgrading.
Update import statements to `from altair.datasets import data`. If encountering `KeyError` for column names, check the dataset documentation or inspect the DataFrame for updated column names.
For non-Jupyter environments, ensure you explicitly call `chart.save('chart.html')`, `chart.to_json()`, or configure a renderer like `alt.renderers.enable('altair_saver')` (requires `vl-convert-python`).To resolve this, install `libgcc` and `libstdc++` in your Alpine environment or Dockerfile before installing Python packages that rely on Rust extensions. For example, using `apk add libgcc libstdc++`.
Install Altair using pip: `pip install altair`.
Upgrade Altair to the latest version: `pip install --upgrade altair`.
Rename or remove the local 'altair.py' file to avoid the naming conflict.
Upgrade 'jsonschema' to a compatible version: `pip install 'jsonschema>=3.0,<4.0'`.
Ensure compatibility between Altair and dependent libraries by installing compatible versions or upgrading dependent libraries.