Skip to content

Viz 01: Unify cluster palette and add discrete palette#1716

Open
Doresic wants to merge 5 commits into
developfrom
viz-01-cluster-palette
Open

Viz 01: Unify cluster palette and add discrete palette#1716
Doresic wants to merge 5 commits into
developfrom
viz-01-cluster-palette

Conversation

@Doresic
Copy link
Copy Markdown
Contributor

@Doresic Doresic commented May 26, 2026

The cluster-coloured plotters (waterfall, parameters, optimization_stats, optimizer_history, profiles) all had their cluster palette hardcoded with no user override path. That default sometimes produced indistinguishable cluster colours. As @PaulJonasJost suggested, a default categorical palette works better. One can change it using a style_kwargs override path. I also added a guarantee the palette stays far from the MLE (default red) and isolated point (default grey) colors.

Main changes:

  • new pypesto/visualize/_style.py with the reserved colours (MLE_COLOR = tab:red for the best cluster, OUTLIER_COLOR for singletons) and the cycled palette source (CMAP_DISCRETE, default "tab10"), plus a small resolve_style helper
  • _build_cluster_palette samples non-best cluster colours from cmap_discrete with a small distance filter — that way the reserved best/outlier colours stay visually distinct from the cycled ones even when someone passes a cmap that happens to contain red or grey
  • style: dict | None threaded through assign_clustered_colors, assign_colors, assign_colors_for_list, process_result_list
  • the 5 top-level plotters get a new style_kwargs: dict | None = None kwarg; their lowlevel counterparts (waterfall_lowlevel, parameters_lowlevel, optimizer_history_lowlevel, stats_lowlevel) take an already-resolved style: dict | None = None. So resolve_style runs exactly once per call chain at the user-facing boundary.

This is the first in a small series of visualisation PRs. The rest of _style.py (constants for bounds, scatter, colorbars, …) grows incrementally as later PRs polish each visualisation family.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 26, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 90.32258% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.33%. Comparing base (7255fc7) to head (450b571).

Files with missing lines Patch % Lines
pypesto/visualize/_style.py 71.42% 4 Missing ⚠️
pypesto/visualize/clust_color.py 92.30% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1716      +/-   ##
===========================================
- Coverage    84.35%   84.33%   -0.03%     
===========================================
  Files          164      165       +1     
  Lines        14752    14796      +44     
===========================================
+ Hits         12444    12478      +34     
- Misses        2308     2318      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Doresic Doresic marked this pull request as ready for review May 28, 2026 14:19
@Doresic Doresic requested a review from stephanmg as a code owner May 28, 2026 14:19
@Doresic Doresic requested a review from Copilot May 28, 2026 14:19
@Doresic Doresic requested review from PaulJonasJost and vwiela May 28, 2026 14:20
Copy link
Copy Markdown

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

This PR introduces a unified, user-overridable visualization style mechanism for cluster-related coloring across multiple pypesto.visualize plotters, switching defaults to a categorical palette and reserving distinct colors for the MLE and singleton/outlier starts.

Changes:

  • Added pypesto.visualize._style with default style constants and a resolve_style(style_kwargs) helper.
  • Threaded a resolved style dict through color assignment utilities and result-list processing to ensure consistent palette selection.
  • Added style_kwargs to user-facing plotters and style to low-level plotting functions to avoid repeated style resolution.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pypesto/visualize/_style.py New style registry/constants and resolve_style merge+warning helper.
pypesto/visualize/clust_color.py Uses a discrete/categorical palette with filtering to keep MLE/outlier colors distinct; propagates style.
pypesto/visualize/misc.py Threads style into process_result_list so per-result palettes use the resolved style.
pypesto/visualize/waterfall.py Adds style_kwargs and forwards resolved style into coloring/lowlevel routines.
pypesto/visualize/parameters.py Adds style_kwargs and forwards resolved style into coloring/lowlevel routines.
pypesto/visualize/optimizer_history.py Adds style_kwargs and forwards resolved style into coloring/lowlevel routines.
pypesto/visualize/optimization_stats.py Adds style_kwargs and forwards resolved style into coloring/palette selection and lowlevel routines.
pypesto/visualize/profiles.py Adds style_kwargs and forwards resolved style through result/profile-list processing.

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

Comment thread pypesto/visualize/clust_color.py
Comment thread pypesto/visualize/clust_color.py Outdated
Comment thread pypesto/visualize/_style.py
Comment thread pypesto/visualize/_style.py
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.

3 participants