Skip to content

Fix radar_plot axis ranges for asymmetric padding and constant metrics - #3

Closed
tonycoder-hub wants to merge 1 commit into
mainfrom
cursor/fix-radar-plot-axis-ranges-bf74
Closed

Fix radar_plot axis ranges for asymmetric padding and constant metrics#3
tonycoder-hub wants to merge 1 commit into
mainfrom
cursor/fix-radar-plot-axis-ranges-bf74

Conversation

@tonycoder-hub

Copy link
Copy Markdown
Owner

Problem

radar_plot derives each variable's axis range from the observed min/max plus 10% padding:

min_max_per_variable["min"] = min_max_per_variable["min"] - 0.1 * (
    min_max_per_variable["max"] - min_max_per_variable["min"]
)
min_max_per_variable["max"] = min_max_per_variable["max"] + 0.1 * (
    min_max_per_variable["max"] - min_max_per_variable["min"]
)

Two things go wrong here:

  1. Asymmetric padding. The second statement recomputes the span using the min that the first statement already shifted downwards, so the top of every axis is padded by 11% of the data range while the bottom is padded by 10%. For accuracy values of 0.0 and 10.0 the axis ends up as (-1.0, 11.1) instead of (-1.0, 11.0).

  2. Zero-width range for constant metrics. When a metric has the same value for every model the span is 0, so the padding is 0 too and the range collapses to a single point. Matplotlib then warns Attempting to set identical low and high ylims makes transformation singular, and because ComplexRadar._scale_data rescales all other variables into ranges[0], a constant first variable flattens every model onto the same radius — two models with different scores are drawn as identical shapes. If every metric is constant (e.g. a single model), _scale_data divides by zero and the plotted coordinates become NaN.

Fix

Compute the padding once from the original min/max, and fall back to a non-zero padding for variables that only take a single value.

Tests

Two tests added to tests/test_viz.py, both failing before the change and passing after:

  • test_range_padding_is_symmetric asserts the accuracy axis is (-1.0, 11.0).
  • test_metric_with_identical_values asserts that when accuracy is identical across models but precision is not, the two plotted shapes are finite and still differ.
$ MPLBACKEND=Agg python -m pytest tests/test_viz.py -q
4 passed

black, isort and flake8 (repo settings, line length 119) are clean on both changed files.

Open in Web Open in Cursor 

The upper padding was derived from the range after the lower bound had
already been shifted, so the top of each axis was padded by 11% of the
data range instead of 10%. A metric with the same value for every model
also produced a zero-width range, which made matplotlib warn about
singular limits and collapsed every other metric onto a single radius
(or produced NaN coordinates when all metrics were constant).

Co-authored-by: Tony Coder <407243179@qq.com>
@tonycoder-hub
tonycoder-hub marked this pull request as ready for review August 17, 2026 09:51
@tonycoder-hub

Copy link
Copy Markdown
Owner Author

Closing as stale — opened on or before 2026-08-17 and still unmerged.

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