Install Altair using pip . It is highly recommended to work within a Jupyter notebook environment (JupyterLab, VS Code, Colab) for automatic rendering.
# Create and activate a virtual environment python -m venv altair-venv source altair-venv/bin/activate # On Windows: altair-venv\Scripts\activate # Install Altair and dependencies python -m pip install altair pandas notebook Use code with caution. Copied to clipboard 2. Core Concepts: The Chart Object Every Altair chart follows three basic steps: Pass a pandas DataFrame to alt.Chart() . altair
This guide focuses on the for data visualization. 1. Installation & Setup Install Altair using pip
One of Altair's strongest features is the ability to create interactivity (like panning, zooming, and tooltips) by linking chart components. Copied to clipboard 2
Altair allows you to transform data directly within the chart definition, such as calculating averages or sums, using mean , sum , count , etc..
You can save your chart as a JSON file (Vega-Lite spec) or render it as an image/HTML file. chart.save('chart.html') Use code with caution. Copied to clipboard
import altair as alt import pandas as pd # 1. Data data = pd.DataFrame({'a': ['A', 'B', 'C'], 'b': [28, 55, 43]}) # 2. & 3. Chart + Mark + Encoding chart = alt.Chart(data).mark_bar().encode( x='a', y='b' ) # Display (if in notebook) # chart.show() Use code with caution. Copied to clipboard 3. Data Transformation & Aggregation