Skip to content

Sample code for the article on Altair#754

Open
lpozo wants to merge 4 commits intomasterfrom
altair-python
Open

Sample code for the article on Altair#754
lpozo wants to merge 4 commits intomasterfrom
altair-python

Conversation

@lpozo
Copy link
Copy Markdown
Contributor

@lpozo lpozo commented Apr 9, 2026

Where to put new files:

  • New files should go into a top-level subfolder, named after the article slug. For example: my-awesome-article

How to merge your changes:

  1. Make sure the CI code style tests all pass (+ run the automatic code formatter if necessary).
  2. Find an RP Team member on Slack and ask them to review & approve your PR.
  3. Once the PR has one positive ("approved") review, GitHub lets you merge the PR.
  4. 🎉

Copilot AI review requested due to automatic review settings April 9, 2026 08:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new altair-python/ sample-code folder to support the Real Python “Altair: Declarative Charts With Python” tutorial, including several standalone chart examples.

Changes:

  • Added a new article folder with a README linking to the tutorial.
  • Added multiple Altair chart example scripts (bar chart, basic scatter, encoded scatter, faceting, and linked views).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
altair-python/README.md Adds the article-specific README and link to the tutorial.
altair-python/steps.py Simple pandas DataFrame + Altair bar chart example.
altair-python/scatter_basic.py Basic scatter plot example using the movies dataset.
altair-python/scatter_encoding_channels copy.py Scatter plot with additional encoding channels (color/size/tooltip).
altair-python/scatter_faceted.py Faceted scatter plot example using column=.
altair-python/scatter_connected.py Linked selection example combining scatter + filtered bars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +2
import altair as alt
from altair.datasets import data
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename contains a space and the suffix "copy", which makes it awkward to import/execute from shells and looks like an accidental duplicate. Please rename this file to a conventional slug/snake-case name without spaces (and without "copy"), e.g. "scatter_encoding_channels.py".

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +27
color=(
alt.when(brush)
.then("Major Genre:N")
.otherwise(alt.value("lightgray")),
),
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra parentheses around the color= expression are unnecessary and make this already-long line harder to read. Consider removing the redundant parentheses and letting the formatter wrap the chained call for readability.

Suggested change
color=(
alt.when(brush)
.then("Major Genre:N")
.otherwise(alt.value("lightgray")),
),
color=alt.when(brush)
.then("Major Genre:N")
.otherwise(alt.value("lightgray")),

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +16
x="Day",
y="Steps",
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the other examples in this folder, the encodings here don’t specify field types (e.g. Day:N, Steps:Q). Making the types explicit keeps the example consistent and avoids relying on Altair’s type inference if the data source changes.

Suggested change
x="Day",
y="Steps",
x="Day:N",
y="Steps:Q",

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +11
"IMDB Rating",
"Major Genre",
"MPAA Rating",
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dropna() filters on columns that aren’t used in this chart (e.g. IMDB Rating, Major Genre, MPAA Rating), which changes which points appear in the basic scatter plot. Consider dropping NAs only for the fields you actually encode here, or add a short comment explaining why you’re pre-filtering extra columns for consistency with later examples.

Suggested change
"IMDB Rating",
"Major Genre",
"MPAA Rating",

Copilot uses AI. Check for mistakes.
"Worldwide Gross",
"IMDB Rating",
"Major Genre",
"MPAA Rating",
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dropna() filters on "MPAA Rating", but this script doesn’t use that field in any encoding. That will remove additional rows and can change the resulting chart. Consider limiting the subset to only the fields used in this script (or add a comment explaining the broader filtering choice).

Suggested change
"MPAA Rating",

Copilot uses AI. Check for mistakes.
"Worldwide Gross",
"IMDB Rating",
"Major Genre",
"MPAA Rating",
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dropna() filters on "MPAA Rating", but this script doesn’t use that field in any encoding. That will remove additional rows and can change the resulting chart. Consider limiting the subset to only the fields used in this script (or add a comment explaining the broader filtering choice).

Suggested change
"MPAA Rating",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants