Try it: https://ncssm.github.io/chartmatch/
Practice for students learning the datascience Python library (the one used in Berkeley's Data 8 and in NCSSM's Foundations of Data Science). Each problem shows the first 10 rows of a table and a target chart. Students write the code that turns the table into that chart, run it, and see their chart next to the target with feedback.
Python runs entirely in the browser with Pyodide, so there is no server and nothing to install.
- Problems come from recipes (for example "
whereon a category, thengroup,sort,take,barh") applied to 22 datasets. The random part is the details: which column, which filter value, which group function (np.mean,np.median,max,min,sum), how many rows to keep. Filters and top-N limits that the chart can't show are stated in a note above the chart. There are 21 recipes in three levels (easy, medium, hard). - Grading compares what the charts show, not the code text, so any code that draws the right chart is correct.
chartmatch.pyreads the data behind a matplotlib figure (bar labels and lengths, histogram bins, scatter points, line values, axis labels, legend) and compares it with the target. When they differ it explains how: wrong chart type, different columns, missing color groups, too many bars, bars out of order, and so on. - Hints go in two steps (the chart type, then the steps in order) before the answer.
- Scores are kept in the student's own browser (
localStorage); nothing is sent anywhere.
| Path | What it is |
|---|---|
docs/ |
The site GitHub Pages serves. |
docs/chartmatch.py |
Problem recipes, generator, chart comparison, and feedback. Runs in CPython and in Pyodide. |
docs/worker.js |
Starts Pyodide in a Web Worker and passes messages between the page and chartmatch.py. |
docs/data/ |
The practice datasets, trimmed to the columns problems use. |
docs/datascience-0.18.1-py3-none-any.whl |
The datascience package, installed into Pyodide at startup. |
tools/index.template.html |
The page. tools/build.py fills in a pre-rendered first problem and the build settings. |
tools/build.py |
Builds docs/index.html (GitHub Pages) or dist-artifact/ (a self-contained copy). |
tools/test_chartmatch.py |
Stress test for the generator and grader. |
tools/prep_data.py |
Rebuilds docs/data/ from the course repo's dataset collection. |
datascience imports scipy, IPython, folium, and branca when it loads. None of them are used by the chart methods practiced here, so in the browser chartmatch.py replaces them with small stand-in modules instead of downloading them.
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python tools/test_chartmatch.py 300 # every solution grades correct; common mistakes grade wrong
python tools/build.py pages # rebuild docs/index.html after changing the template
python -m http.server --directory docs # then open http://localhost:8000To add a dataset: put a CSV in docs/data/, add it to DATA_FILES in docs/worker.js, and add an entry to DATASETS in docs/chartmatch.py saying which columns can play which roles. To add a kind of problem, write a recipe function and add it to RECIPES.
python tools/build.py artifact makes dist-artifact/, a copy with Pyodide and its packages bundled in instead of loaded from the jsDelivr CDN. That is how the Claude artifact version is published: its host only serves standard web file types, so the .whl and .zip files are renamed with an extra .wasm extension and worker.js adds it back when fetching them.
The datasets were found through Jeremy Singer-Vine's Data Is Plural newsletter. Files are trimmed to a few columns, and rows missing a needed value are removed.
| File | Dataset | Source | Data Is Plural |
|---|---|---|---|
penguins |
Palmer penguins | data | 2020-06-17 |
candy |
Halloween candy rankings (FiveThirtyEight) | data | 2021-10-20 |
pixar |
Pixar films | data | 2024-12-04 |
survivor |
Survivor seasons | data | 2021-05-05 |
volcanoes |
Volcanoes of the world (Smithsonian GVP) | data | 2018-06-06 |
ramen |
Instant ramen ratings (The Ramen Rater) | data | 2018-01-24 |
world_cup |
World Cup group standings | data | 2022-07-20 |
fight_songs |
College fight songs (FiveThirtyEight) | data | 2019-09-04 |
jeans |
Jeans pocket sizes (The Pudding) | data | 2018-08-22 |
peaks |
Himalayan peaks (Himalayan Database) | data | 2018-05-09 |
banknotes |
People on banknotes (The Pudding) | data | 2022-05-18 |
nobel |
Nobel Prize winners | data | 2017-02-08 |
chocolate |
Chocolate bar ratings (Flavors of Cacao) | data | 2022-01-12 |
exoplanets |
NASA Exoplanet Archive | data | 2016-05-11 |
quakes |
USGS earthquakes, magnitude 5.5+ in 2024 | data | 2024-04-17 |
warming |
US warming by state (The Washington Post) | data | 2020-08-12 |
groundhogs |
Groundhog Day predictions | data | 2023-02-08 |
tour |
Tour de France winners | data | 2020-03-11 |
bob_ross |
Bob Ross paintings | data | 2020-12-09 |
yearbook |
Big hair in yearbook photos (The Pudding) | data | 2019-12-11 |
baby |
Child Health and Development Studies births (via Data 8) | Data 8 | |
galton |
Galton's family heights (via Data 8) | Data 8 |
Each dataset remains under its original source's terms.