Skip to content

docs: Add an Andrews curves example to the gallery - #4049

Merged
mattijn merged 4 commits into
vega:mainfrom
kyo5uke:andrews-curves-example
Jun 6, 2026
Merged

mattijn merged 4 commits into
vega:mainfrom
kyo5uke:andrews-curves-example

Conversation

@kyo5uke

@kyo5uke kyo5uke commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Closes #2470.

Description

Adds an Andrews Curves example to the example gallery, as requested in #2470 (labelled documentation / good first issue).

Andrews curves visualize clusters in multivariate data by mapping each observation to a finite Fourier series and drawing it as a single line, so observations in the same group trace out similar shapes. The example uses the penguins dataset from altair.datasets and colours each curve by species.

As described in the contributing guide, the example is added in both syntaxes, under the Advanced Calculations category:

  • tests/examples_arguments_syntax/andrews_curves.py
  • tests/examples_methods_syntax/andrews_curves.py

A few implementation notes:

  • The Fourier transform is computed with vectorized NumPy and follows the standard form f(t) = x1/√2 + x2·sin(t) + x3·cos(t) + x4·sin(2t), with each dimension normalized to (0, 1) so no single column dominates.
  • To stay well within the gallery test suite's default max_rows limit, an even sample of 15 rows per species is taken (3 × 15 observations × 100 samples = 4500 rows), which keeps all three species clearly represented.

Tests & Docs

The example is itself a documentation/gallery item and is covered by the existing tests/test_examples.py suite. I verified locally (altair 6.1.0) that, for both files, the harness flow passes:

  • eval_block returns a Chart;
  • chart.to_dict() succeeds;
  • the to_json → from_json → to_json round-trip is stable;
  • the generated data is 4500 rows (under the default max_rows=5000).

I did not run the full Sphinx docs/image build locally, so the rendered thumbnail has not been generated on my machine.

mattijn
mattijn previously requested changes Jun 5, 2026

@mattijn mattijn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR and nice looking example! I have some minor inline suggestions. We prefer None over "" in empty titles, and we have a preference to square default examples (see marimo-team/marimo#8596 for a recent reasoning for this).

(btw looking forward to have this feature in VL upstream to eventually build some interaction with these type of plots.)

Again thanks for the PR!

@kyo5uke

kyo5uke commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @mattijn! Applied both suggestions in the arguments- and methods-syntax files: used title=None for the empty y-axis title, and removed the explicit .properties(width=600, height=400) so it falls back to the default square size.

@mattijn
mattijn enabled auto-merge (squash) June 6, 2026 09:59
@mattijn
mattijn dismissed their stale review June 6, 2026 21:42

new commits have been added

@mattijn
mattijn merged commit 3b1acf6 into vega:main Jun 6, 2026
14 checks passed
@mattijn

mattijn commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Thanks! looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Andrews Curves example

3 participants