Skip to content

Comments

Add dynamic color scaling support using mean and standard deviation#94

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-91
Draft

Add dynamic color scaling support using mean and standard deviation#94
Copilot wants to merge 2 commits intomainfrom
copilot/fix-91

Conversation

Copy link
Contributor

Copilot AI commented Jun 3, 2025

This PR adds support for dynamic color scaling in plots using mean and standard deviation, addressing the need for more robust color mapping that is less sensitive to outliers.

Problem

Currently, the plot color mapping in Tab-right assumes that error or metric values use min/max normalization, which can be problematic when:

  • Data contains outliers that dominate the color scale
  • Consistent color meaning across plots is required
  • Users need more robust, data-driven scaling methods

Solution

Added a new normalize_scores() function and updated all plotting functions to support two scaling methods:

1. MinMax Scaling (existing behavior, default)

# Uses full data range [min, max]
plot_single_segmentation_mp(df, scaling_method="minmax")

2. Standard Deviation Scaling (new)

# Uses [mean - k*std, mean + k*std] range (default k=2)
plot_single_segmentation_mp(df, scaling_method="std", scaling_k=2.0)

Key Features

  • Robust to outliers: "std" method provides consistent color interpretation even with extreme values
  • Configurable range: The k parameter controls how many standard deviations to include
  • Backward compatible: All existing code continues to work unchanged
  • Comprehensive support: Works with both single and double segmentation plots, Plotly and Matplotlib backends

Example Usage

import pandas as pd
from tab_right.plotting.plot_segmentations import plot_single_segmentation_mp

# Data with an outlier
df = pd.DataFrame({
    'segment_id': [1, 2, 3, 4],
    'segment_name': ['A', 'B', 'C', 'D'],
    'score': [0.1, 0.15, 0.12, 0.95]  # 0.95 is an outlier
})

# Robust scaling (recommended with outliers)
fig = plot_single_segmentation_mp(df, scaling_method="std")

# Traditional scaling (sensitive to outliers)  
fig = plot_single_segmentation_mp(df, scaling_method="minmax")

Benefits

  • 🎯 More robust color mapping - less sensitive to outliers
  • 🎨 Consistent interpretation - colors have consistent meaning across plots
  • 🔧 Greater flexibility - users can choose appropriate scaling for their data
  • ⬅️ Backward compatible - no breaking changes to existing code

Fixes #91.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: eh-main-bot <171766998+eh-main-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Support dynamic color scaling in plots using mean and standard deviation Add dynamic color scaling support using mean and standard deviation Jun 3, 2025
Copilot AI requested a review from EH-MLS June 3, 2025 17:35
Copilot finished work on behalf of EH-MLS June 3, 2025 17:35
@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

❌ Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.74%. Comparing base (081f151) to head (6cbedfd).
⚠️ Report is 209 commits behind head on main.

Files with missing lines Patch % Lines
tab_right/plotting/plot_segmentations.py 92.72% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
- Coverage   95.78%   95.74%   -0.05%     
==========================================
  Files          19       19              
  Lines         736      776      +40     
==========================================
+ Hits          705      743      +38     
- Misses         31       33       +2     

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

@EH-MLS
Copy link
Collaborator

EH-MLS commented Jun 3, 2025

@copilot make sure 'make check' is pass.

Copy link
Contributor Author

Copilot AI commented Jun 3, 2025

@copilot make sure 'make check' is pass.

make check passes successfully. All pre-commit hooks (debug statements, fix end of files, trim trailing whitespace, don't commit to branch, nb-clean, ruff format, and ruff) completed without issues.

Copilot finished work on behalf of EH-MLS June 3, 2025 17:57
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.

Support dynamic color scaling in plots using mean and standard deviation

2 participants