Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- `scorecard` draws the PhD-defense-deck look: text is the raw value, colour the percent better
than a baseline on the fixed 11-band `scorecard_skill_cmap` (blue better, red worse).
New arguments: `color_values` and `text` (colour numbers apart from printed ones),
`reference_row` (outlined, grey, labelled `baseline_suffix`) and `reference_cells` (one outlined
cell per column), both also supplying `reference`; `unresolved` (grey cell with grey value),
`na_text`, `row_groups` and `row_group_gap`, `group_rule`, `cell_in`, `font_scale` and `floor`.
- `scorecard_skill_cmap()` returns the reversed `scorecard_diverging_cmap` pair (higher is better).
- `skill_gap(mode="percent", floor=...)` gives the percent better than the reference.
- Gallery example `34_scorecard_baseline`.

### Changed

- **Behaviour change** of `scorecard` defaults: `highlight_best=False`; with no baseline cells are
ranked per column on the skill palette (blue best) instead of `RdYlGn`; `reference=` colours by
percent better (with `uncertainty=` as before, in standard errors, on the same palette); `cmap=None`;
`group_gap=0.35` (was 0.6); `na_color="#e8e8e8"`; `colorbar_label=None` gives
"% better than the baseline" (pass `""` for none).
- **Behaviour change**: a new figure is sized from its cells (`cell_in`, 0.42 in) rather than from
`width="half"`; `width=` still fixes the figure width and solves the cell size. `square` only
acts on a given `ax`.
- **Behaviour change**: column headings are horizontal and wrapped, units are a grey second line,
group titles are regular weight above a 1.6 pt rule, row and column labels are text rather than
ticks, and the colourbar is half the grid width with ticks at the band edges and pointed ends.
- `outline_boxes` draws unfilled rectangles (`fill=False`).

### Notes

- `nicefigs.cmap("RdBu")` returns `RdBu_r` (red high), so `scorecard(reference=..., cmap="RdBu")`
colours better cells red. Pass `matplotlib.colormaps["RdBu"]` or use the default scale.

## [1.2.0] - 2026-11-20

### Added
Expand Down
Binary file modified docs/assets/20_scorecard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/guide/plots-scorecard-diverging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/guide/plots-scorecard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ each item, a reference line at the null, and a headline `summary` annotation.
### 20 — Scorecard {#scorecard}

[`nicefigs.scorecard`][nicefigs.scorecard] renders a model×metric table as
coloured cells — normalised independently per column and respecting each
metric's `direction` (lower/higher better) — with the best model per metric
outlined.
coloured cells. With no baseline, cells are ranked independently per column,
respecting each metric's `direction` (lower/higher better), on the skill palette.

![Scorecard](gallery/20_scorecard.png)

Expand Down Expand Up @@ -319,6 +318,21 @@ horizontal bar with the colormap's extend triangles.
--8<-- "examples/30_scorecard_diverging.py"
```

### 34 — Scorecard against a baseline {#scorecard-baseline}

The default look of [`nicefigs.scorecard`][nicefigs.scorecard]: cell text is the
raw value and colour is the percent better than the baseline row, on the fixed
11-band scale [`scorecard_skill_cmap`][nicefigs.scorecard_skill_cmap] (blue better,
red worse). The baseline row is outlined and labelled, cells within the noise floor
stay grey, columns are grouped under titled rules, and the colourbar carries the
band edges with pointed ends.

![Scorecard against a baseline](gallery/34_scorecard_baseline.png)

```python
--8<-- "examples/34_scorecard_baseline.py"
```

## Budgets

### 33 — Flux diagram {#flux-diagram}
Expand Down
Binary file modified docs/gallery/20_scorecard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/gallery/30_scorecard_diverging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/34_scorecard_baseline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 43 additions & 21 deletions docs/guide/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,39 +304,60 @@ value offset beside each.

## Scorecards

[`scorecard()`][nicefigs.scorecard] renders a model × metric table as
coloured cells. By default each column is ranked on its own, using each
metric's `direction` from [`DIRECTIONS`][nicefigs.DIRECTIONS], and the best
cell per column is outlined.
[`scorecard()`][nicefigs.scorecard] renders a model × metric table as coloured
cells. The text of a cell is the raw value; its colour is the percent it is
better than a baseline, on one fixed 11-band scale
([`scorecard_skill_cmap()`][nicefigs.scorecard_skill_cmap]): blue is better, red
worse, light grey within about 1 %. The baseline is a row (`reference_row`), drawn
grey inside one outline and labelled "(baseline)", or one outlined cell per column
(`reference_cells`). Missing values print "n/a"; cells whose difference is below
the noise (`unresolved`) stay grey and print their value in grey. `col_groups` and
`row_groups` separate groups with a gap, and column groups get a title with a rule.
The figure is sized from its cells (`cell_in`, 0.42 in by default) with fonts at their
printed point sizes.

```python
import numpy as np

import nicefigs as nf
from nicefigs import data

nf.set_theme("paper")
ms = data.model_scores()
values = np.array(
[[np.mean(ms["scores"][m][model]["daily"]) for m in ms["metrics"]] for model in ms["models"]]
rmse = np.array(
[
[2.10, 4.56, 6.42, 0.765, 0.908, 1.03],
[1.60, 4.78, 6.72, 0.926, 0.694, 0.866],
[1.55, 4.53, 6.66, 0.788, 0.693, 0.841],
]
)
cols = ["surface SH", "surface NH", "tower", "gradient", "OCO-2", "OCO-3"]
percent = nf.skill_gap(rmse, rmse[0], direction="lower_better", mode="percent")
ax = nf.scorecard(
values,
row_labels=ms["models"],
col_labels=ms["metrics"],
direction={"RMSE": "lower_better", "Bias": "target", "R$^2$": "higher_better"},
col_units={"RMSE": "mm"},
rmse,
row_labels=["CT2026", "model A", "model B"],
col_labels=cols,
direction=dict.fromkeys(cols, "lower_better"),
reference_row="CT2026",
unresolved=np.abs(percent) < 2.0,
col_groups=["In situ"] * 3 + ["Gradient"] + ["Column"] * 2,
col_units=dict.fromkeys(cols, "ppm"),
cell_format="{:#.3g}",
colorbar=True,
)
```

![Scorecard](../assets/guide/plots-scorecard.png)

Bias is ranked by closeness to zero, the default `target`.
The colours can also come from numbers other than the printed ones: `color_values=`
takes the percent directly and `text=` the printed entries. `reference=` measures
against any array, and with `uncertainty=` in standard errors instead of percent.
Without any baseline, cells are coloured by the rank within their column on a
continuous version of the palette, using each metric's `direction` from
[`DIRECTIONS`][nicefigs.DIRECTIONS]; `highlight_best=True` outlines the best cell
per column.

To colour cells by their value instead, pass a `norm`, for example from
[`scorecard_diverging_cmap()`][nicefigs.scorecard_diverging_cmap].
`col_groups` gaps and titles groups of columns, `square=True` forces square
cells and `colorbar=True` adds a colorbar.
To colour cells by their printed value instead, pass a `norm`, for example from
[`scorecard_diverging_cmap()`][nicefigs.scorecard_diverging_cmap], together with its
`cmap`.

```python
import numpy as np
Expand Down Expand Up @@ -368,9 +389,10 @@ Negative differences, an improvement over the baseline, are blue; the outline
marks the lowest value per column.

[`skill_gap()`][nicefigs.skill_gap] computes the signed distance of each value
from a reference, positive where the value is better. Passing `reference=` to
`scorecard` colours cells by this gap, so metrics in different units share one
scale.
from a reference, positive where the value is better; `mode="percent"` gives the
percent better than the reference, with an optional `floor` for references near zero.
Passing `reference=` to `scorecard` colours cells by this gap, so metrics in different
units share one scale.

```python
import nicefigs as nf
Expand Down
44 changes: 44 additions & 0 deletions examples/34_scorecard_baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Scorecard of three models against a baseline row: text is the raw value, colour is percent better."""

import numpy as np

import nicefigs as nf


def make():
nf.set_theme("paper")
rows = ["CT2026", "model A", "model B", "model C"]
cols = ["surface SH", "surface NH", "tower", "aircraft", "ship", "gradient", "OCO-2", "OCO-3", "TCCON"]
groups = ["In situ"] * 5 + ["Gradient"] + ["Column"] * 3
# Synthetic RMSE (ppm); smaller is better.
rmse = np.array(
[
[2.10, 4.56, 6.42, 1.92, 2.97, 0.765, 0.908, 1.03, 0.898],
[1.60, 4.78, 6.72, 2.11, 3.21, 0.926, 0.694, 0.866, 0.916],
[1.62, 4.78, 6.75, 2.03, 2.86, 0.800, 0.691, 0.839, 0.911],
[1.55, 4.53, 6.66, 2.05, 2.73, 0.788, 0.693, 0.841, 1.05],
]
)
# Cells whose difference to the baseline is below the noise floor of their column stay grey.
noise = np.array([2, 1, 2, 2, 2, 6, 2, 2, 2.5])
percent = nf.skill_gap(rmse, rmse[0], direction="lower_better", mode="percent")
ax = nf.scorecard(
rmse,
row_labels=rows,
col_labels=cols,
direction=dict.fromkeys(cols, "lower_better"),
reference_row="CT2026",
unresolved=np.abs(percent) < noise,
col_groups=groups,
col_units=dict.fromkeys(cols, "ppm"),
cell_format="{:#.3g}",
colorbar=True,
)
return ax.figure


if __name__ == "__main__":
import matplotlib

matplotlib.use("Agg")
nf.save(make(), "34_scorecard_baseline", formats=("png", "pdf"))
2 changes: 2 additions & 0 deletions src/nicefigs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
role_color,
role_style,
scorecard_diverging_cmap,
scorecard_skill_cmap,
symmetric_limits,
)
from .panels import (
Expand Down Expand Up @@ -182,6 +183,7 @@
"robust_limits",
"symmetric_limits",
"scorecard_diverging_cmap",
"scorecard_skill_cmap",
"SCORECARD_DIVERGING_BOUNDARIES",
# role palette
"ROLES",
Expand Down
Loading
Loading