Altair (720p • 1080p)
If your data relies on a pandas index, use .reset_index() before passing it to Altair.
Install Altair using pip . It is highly recommended to work within a Jupyter notebook environment (JupyterLab, VS Code, Colab) for automatic rendering. altair
Map data columns to visual properties (e.g., .encode(x='column1', y='column2') ). Example: Simple Bar Chart If your data relies on a pandas index, use
Create a specific (e.g., click a bar to filter data)? Map data columns to visual properties (e
alt.Chart(data).mark_bar().encode( x=alt.X('a', title='Category'), y=alt.Y('b', title='Value'), color='a' # Color by category ).properties( title='My First Altair Chart', width=400, height=300 ) Use code with caution. Copied to clipboard 5. Interaction
One of Altair's strongest features is the ability to create interactivity (like panning, zooming, and tooltips) by linking chart components.
# 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() .