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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ to [Semantic Versioning](https://semver.org/).

### Changed

- **Behaviour change**: `hovmoller`, `cross_section`, `cross_section_panels` and `heatmap` default to
the sequential colormap (`inferno`) instead of `Spectral_r`; `diff=True` still defaults to `RdBu_r`
(`cmap=None` in `hovmoller` and `cross_section`), and an explicit `cmap` is now kept with `diff=True`.
- **Behaviour change**: `grouped_bars` puts its legend in a row above the axes (right-aligned, no frame)
instead of `loc="best"`, which could cover bars; `pareto` labels `baselines` at the left edge on a
white backing.
- `cross_section` no longer sets a bare `"[hPa]"` label when `ylabel=""` (likewise `xlabel`).
- **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`;
Expand Down
Binary file modified docs/assets/01_global_map.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/05_ternary_map.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/14_agreement.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/17_model_comparison.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/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/23_composite_figure.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/animation-maps.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/animation-panels.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/colormaps-artist.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/colormaps-bivariate.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/colormaps-elevation.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/colormaps-landcover.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/colormaps-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/colormaps-ternary.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/figures-ax-title.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/figures-facet.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/figures-grid.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/figures-labels.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/figures-legend-row.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/figures-overlaps.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/figures-reference-line.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/figures-row-col.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/figures-single.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/maps-binned.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/maps-categorical.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/maps-inset-hist.png
Binary file modified docs/assets/guide/maps-panels.png
Binary file modified docs/assets/guide/maps-regional.png
Binary file modified docs/assets/guide/maps-scatter.png
Binary file modified docs/assets/guide/maps-ternary.png
Binary file modified docs/assets/guide/maps-tri.png
Binary file modified docs/assets/guide/maps-xarray.png
Binary file modified docs/assets/guide/plots-agreement.png
Binary file modified docs/assets/guide/plots-bars.png
Binary file modified docs/assets/guide/plots-caterpillar.png
Binary file modified docs/assets/guide/plots-cross-section.png
Binary file modified docs/assets/guide/plots-flowchart.png
Binary file modified docs/assets/guide/plots-flux-diagram-panels.png
Binary file modified docs/assets/guide/plots-flux-diagram.png
Binary file modified docs/assets/guide/plots-hovmoller.png
Binary file modified docs/assets/guide/plots-image-grid.png
Binary file modified docs/assets/guide/plots-image-heatmap.png
Binary file modified docs/assets/guide/plots-model-comparison.png
Binary file modified docs/assets/guide/plots-pareto.png
Binary file modified docs/assets/guide/plots-pca-rgb.png
Binary file modified docs/assets/guide/plots-profile-band.png
Binary file modified docs/assets/guide/plots-profile.png
Binary file modified docs/assets/guide/plots-scatter.png
Binary file modified docs/assets/guide/plots-scorecard-diverging.png
Binary file modified docs/assets/guide/plots-scorecard.png
Binary file modified docs/assets/guide/plots-spectrum.png
Binary file modified docs/assets/guide/plots-taylor.png
Binary file modified docs/assets/guide/plots-timeseries-obs.png
Binary file modified docs/assets/guide/plots-timeseries.png
Binary file modified docs/assets/guide/quickstart-conventions.png
Binary file modified docs/assets/guide/quickstart-map.png
Binary file modified docs/assets/guide/quickstart-style.png
Binary file modified docs/assets/guide/styling-roles.png
Binary file modified docs/assets/guide/styling-talk.png
9 changes: 5 additions & 4 deletions docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,18 @@ both take a plain `ax` so they drop into any layout.
--8<-- "examples/21_bars.py"
```

### 30 — Scorecard, diverging {#scorecard-diverging}
### 30 — Scorecard, explicit norm {#scorecard-diverging}

[`nicefigs.scorecard`][nicefigs.scorecard]'s opt-in kwargs for a
WeatherBench2-style skill scorecard: an explicit diverging `norm` (here
The explicit-norm path of [`nicefigs.scorecard`][nicefigs.scorecard], for when the
printed numbers are themselves the quantity to colour (the default, baseline-anchored
look is example 34): an explicit diverging `norm` (here
[`scorecard_diverging_cmap`][nicefigs.scorecard_diverging_cmap]) colours
cells by their *actual* percent-difference value anchored at zero instead of
per-column goodness ranking; `col_groups` clusters columns with a gap and a
group title; `square=True` forces square cells; `colorbar=True` draws a
horizontal bar with the colormap's extend triangles.

![Scorecard, diverging](gallery/30_scorecard_diverging.png)
![Scorecard, explicit norm](gallery/30_scorecard_diverging.png)

```python
--8<-- "examples/30_scorecard_diverging.py"
Expand Down
Binary file modified docs/gallery/01_global_map.png
Binary file modified docs/gallery/02_anomaly_map.png
Binary file modified docs/gallery/03_regional_map.png
Binary file modified docs/gallery/04_shared_colorbar.png
Binary file modified docs/gallery/05_ternary_map.png
Binary file modified docs/gallery/06_bivariate.png
Binary file modified docs/gallery/07_image_grid.png
Binary file modified docs/gallery/08_landcover_rgb.png
Binary file modified docs/gallery/09_heatmap.png
Binary file modified docs/gallery/10_elevation.png
Binary file modified docs/gallery/11_ternary.png
Binary file modified docs/gallery/12_artist_palettes.png
Binary file modified docs/gallery/13_scatter.png
Binary file modified docs/gallery/14_agreement.png
Binary file modified docs/gallery/15_timeseries.png
Binary file modified docs/gallery/16_station_timeseries.png
Binary file modified docs/gallery/17_model_comparison.png
Binary file modified docs/gallery/18_pareto.png
Binary file modified docs/gallery/19_caterpillar.png
Binary file modified docs/gallery/20_scorecard.png
Binary file modified docs/gallery/21_bars.png
Binary file modified docs/gallery/22_cross_section.png
Binary file modified docs/gallery/23_composite_figure.png
Binary file modified docs/gallery/24_animation.gif
Binary file modified docs/gallery/25_taylor.png
Binary file modified docs/gallery/26_hovmoller.png
Binary file modified docs/gallery/27_profile.png
Binary file modified docs/gallery/28_render_animation.gif
Binary file modified docs/gallery/29_timeseries_obs_hue.png
Binary file modified docs/gallery/30_scorecard_diverging.png
Binary file modified docs/gallery/31_panel_label_with_title.png
Binary file modified docs/gallery/32_spectrum.png
Binary file modified docs/gallery/33_flux_diagram.png
Binary file modified docs/gallery/34_scorecard_baseline.png
Binary file modified docs/gallery/35_schematic.png
Binary file modified docs/gallery/guide_maps_data.png
2 changes: 1 addition & 1 deletion docs/guide/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ nf.set_theme("paper")

da = data.global_dataarray()
lon, lat, field = nf.from_xarray(da)
fig, ax, mappable = nf.map(da, cmap="Spectral_r", colorbar_label="t2m [°C]")
fig, ax, mappable = nf.map(da, cmap="RdYlBu_r", colorbar_label="t2m [°C]")
print(da.dims, field.shape)
```

Expand Down
11 changes: 9 additions & 2 deletions docs/guide/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ from nicefigs import data

nf.set_theme("paper")
images = [data.regional_grid(seed=i)[2] for i in range(6)]
lim = max(abs(img).max() for img in images)
fig, axes = nf.image_grid(
images,
nrows=2,
ncols=3,
width="full",
cmap="Spectral_r",
colorbar_label="value",
cmap="RdBu_r",
vmin=-lim,
vmax=lim,
panel_aspect=0.62,
hspace=0.3,
colorbar_label="anomaly [σ]",
titles=[f"member {i + 1}" for i in range(6)],
)
nf.label_panels(axes)
Expand Down Expand Up @@ -81,6 +86,8 @@ ax, artists = nf.scatter(
d["x"], d["y"], group=d["group"], size=d["size"], size_label="area [km²]", alpha=0.8
)
nf.set_labels(ax, "predictor", "response")
ax.set_xlim(-0.5, 12.5)
ax.set_ylim(top=11.5)
print(sorted(artists))
```

Expand Down
6 changes: 3 additions & 3 deletions examples/03_regional_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def make():
projection="platecarree",
kind="binned",
bin_deg=0.15,
cmap="Spectral_r",
diverging=True,
inset_hist=False,
cbar=True,
colorbar_label="soil moisture [m³ m⁻³]",
colorbar_label="soil-moisture anomaly [σ]",
borders=True,
title="Regional field (Central Europe)",
title="Regional anomaly (Central Europe)",
)
return fig

Expand Down
9 changes: 7 additions & 2 deletions examples/07_image_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
def make():
nf.set_theme("paper")
imgs = [data.regional_grid(seed=i)[2] for i in range(6)]
lim = max(abs(img).max() for img in imgs) # signed anomalies: colour limits symmetric about zero
fig, axes = nf.image_grid(
imgs,
nrows=2,
ncols=3,
cmap="Spectral_r",
colorbar_label="value",
cmap="RdBu_r",
vmin=-lim,
vmax=lim,
panel_aspect=0.62,
hspace=0.3,
colorbar_label="anomaly [σ]",
titles=[f"member {i + 1}" for i in range(6)],
)
nf.label_panels(axes)
Expand Down
1 change: 0 additions & 1 deletion examples/09_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def make():
data.heatmap_matrix(shape=(6, 9)),
row_labels=[f"model {i + 1}" for i in range(6)],
col_labels=[f"lead {i + 1}" for i in range(9)],
cmap="Spectral_r",
annotate=True,
ax=ax,
)
Expand Down
2 changes: 2 additions & 0 deletions examples/13_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def make():
ax=ax,
)
nf.set_labels(ax, "predictor", "response")
ax.set_xlim(-0.5, 12.5) # headroom on the right for the size legend
ax.set_ylim(top=11.5) # and on top for the group legend
return fig


Expand Down
1 change: 1 addition & 0 deletions examples/15_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def make():
yunits="degC",
title="Daily air temperature",
)
ax.set_ylim(top=46) # headroom above the seasonal peak for the legend
return ax.figure


Expand Down
4 changes: 2 additions & 2 deletions examples/23_composite_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

def make():
nf.set_theme("paper")
fig = nf.figure(width="full", aspect=0.62)
gs = fig.add_gridspec(2, 2, height_ratios=[1.15, 1.0], hspace=0.42, wspace=0.32)
fig = nf.figure(width="full", aspect=0.8)
gs = fig.add_gridspec(2, 2, height_ratios=[1.5, 1.0], hspace=0.42, wspace=0.32)

# (a) global map spanning the top row
ax_map, ccrs = nf.make_map_axes(fig, gs[0, :], projection="robinson")
Expand Down
9 changes: 7 additions & 2 deletions examples/30_scorecard_diverging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Scorecard with the WeatherBench2-inspired diverging colormap, grouped columns, and a colour bar."""
"""Scorecard coloured by its printed values through an explicit ``norm`` (the colour-by-value path).

The default, baseline-anchored look (text is the raw value, colour the percent better than a
baseline) is shown in example 34. Pass ``cmap`` and ``norm`` as here when the printed numbers
are themselves the quantity to colour, e.g. percent differences.
"""

import numpy as np

Expand Down Expand Up @@ -33,7 +38,7 @@ def make():
cell_format="{:+.0f}",
colorbar=True,
colorbar_label="RMSE difference vs. Persistence [%]",
title="Scorecard vs. Persistence baseline",
title="Colour = printed value (explicit norm)",
)
return ax.figure

Expand Down
3 changes: 2 additions & 1 deletion examples/guide_maps_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
def make():
nf.set_theme("paper")
fig = nf.figure(width="full", aspect=0.3)
fig.subplots_adjust(wspace=0.28)

# (a) gridded field (the xarray/zarr case) — pcolormesh
ax1, ccrs = nf.make_map_axes(fig, (1, 2, 1), projection="robinson")
lon, lat, z = data.global_grid(res=2.0)
nf.draw_background(ax1, ccrs)
ax1.set_extent(nf.maps.ANTARCTICA_CUTOFF_EXTENT, crs=ccrs.PlateCarree())
_, m1 = nf.raster_map(lon, lat, z, ccrs=ccrs, cmap="Spectral_r", ax=ax1)
_, m1 = nf.raster_map(lon, lat, z, ccrs=ccrs, cmap="RdYlBu_r", ax=ax1)
nf.colorbar(m1, ax1, label="T [°C]")
nf.panel_label(ax1, "a", "gridded (pcolormesh)")

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ all = [
docs = [
"mkdocs-material>=9.5",
"mkdocstrings[python]>=0.24",
"pymdown-extensions>=10,<12",
]
dev = [
"nicefigs[maps,xarray]",
Expand Down
12 changes: 10 additions & 2 deletions src/nicefigs/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def grouped(
value_label: y-axis label.
value_units: Unit appended to ``value_label``.
baseline: y value of a dashed reference line.
legend: Add a legend when there is more than one series.
legend: Add a legend when there is more than one series, in a row above the axes
(right-aligned, no frame) so that it never covers a bar.
rotation: Category tick-label rotation (degrees).
edgecolor: Bar edge colour.

Expand Down Expand Up @@ -100,7 +101,14 @@ def grouped(
ax.grid(axis="y", alpha=0.15, linewidth=0.5)
ax.set_axisbelow(True)
if legend and nser > 1:
ax.legend(loc="best", fontsize=th.fs_legend, ncol=min(nser, 3))
ax.legend(
loc="lower right",
bbox_to_anchor=(1.0, 1.0),
borderaxespad=0.2,
frameon=False,
fontsize=th.fs_legend,
ncol=min(nser, 4),
)
return ax


Expand Down
16 changes: 8 additions & 8 deletions src/nicefigs/hovmoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import numpy as np

from .palettes import DEFAULTS, robust_limits, symmetric_limits
from .palettes import cmap as resolve_cmap
from .palettes import robust_limits, symmetric_limits
from .style import get_theme
from .units import axis_label

Expand All @@ -33,7 +33,7 @@ def hovmoller(
z: ArrayLike,
*,
ax: Axes | None = None,
cmap: str | Colormap = "Spectral_r",
cmap: str | Colormap | None = None,
vmin: float | None = None,
vmax: float | None = None,
norm: Normalize | None = None,
Expand All @@ -57,12 +57,12 @@ def hovmoller(
y: Spatial coordinate of length ``ny``, e.g. latitude.
z: Field of shape ``(nt, ny)``.
ax: Axes to draw on; a new figure is created when ``None``.
cmap: Colormap name or object.
cmap: Colormap name or object; ``None`` picks ``RdBu_r`` for ``diff`` and the sequential
default (``inferno``) otherwise.
vmin: Lower colour limit; derived from ``z`` if ``None``.
vmax: Upper colour limit; derived from ``z`` if ``None``.
norm: Colour normalisation; overrides ``vmin``/``vmax``.
diff: Treat ``z`` as a difference: symmetric limits, and ``RdBu_r`` when
``cmap`` is left at its default.
diff: Treat ``z`` as a difference: symmetric limits about zero.
robust: Derive limits from the 2nd/98th percentiles instead of min/max.
colorbar: Draw a colorbar. Defaults to ``True`` when this call creates the
figure and ``False`` when drawing onto a supplied ``ax``.
Expand All @@ -82,8 +82,8 @@ def hovmoller(
th = get_theme()
y = np.asarray(y, dtype=float)
z = np.asarray(z, dtype=float)
if diff and cmap == "Spectral_r":
cmap = "RdBu_r"
if cmap is None:
cmap = "RdBu_r" if diff else DEFAULTS["sequential"]
if norm is None and (vmin is None or vmax is None):
if diff:
lo, hi = symmetric_limits(z)
Expand Down Expand Up @@ -139,7 +139,7 @@ def hovmoller_panels(
y: ArrayLike,
*,
diff_fields: Collection[str] = (),
value_cmap: str | Colormap = "Spectral_r",
value_cmap: str | Colormap = DEFAULTS["sequential"],
diff_cmap: str | Colormap = "RdBu_r",
value_label: str = "",
diff_label: str = "",
Expand Down
4 changes: 2 additions & 2 deletions src/nicefigs/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from .colorbars import colorbar
from .figure import subplots
from .palettes import DEFAULTS, robust_limits
from .palettes import cmap as resolve_cmap
from .palettes import robust_limits
from .style import get_theme

if TYPE_CHECKING:
Expand Down Expand Up @@ -247,7 +247,7 @@ def heatmap(
ax: Axes | None = None,
row_labels: Sequence[str] | None = None,
col_labels: Sequence[str] | None = None,
cmap: str = "Spectral_r",
cmap: str = DEFAULTS["sequential"],
vmin: float | None = None,
vmax: float | None = None,
norm: Normalize | None = None,
Expand Down
11 changes: 7 additions & 4 deletions src/nicefigs/pareto.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def pareto(
frontier_per_group: Draw one colour-matched frontier per ``group``
instead of one for all points.
frontier_kwargs: Overrides for the frontier :meth:`~matplotlib.axes.Axes.plot` style.
baselines: ``{label: y}`` labelled horizontal reference lines.
baselines: ``{label: y}`` horizontal reference lines, labelled at the left edge on a white
backing.
baseline_colors: ``{label: colour}`` for ``baselines``; defaults to greys.
xlabel: x-axis label.
ylabel: y-axis label.
Expand Down Expand Up @@ -220,14 +221,16 @@ def pareto(
col = bc.get(label, fallback[i % len(fallback)])
ax.axhline(val, color=col, linestyle=":", linewidth=0.8, zorder=2)
ax.text(
0.995,
0.01,
val,
f" {label} ({val:.3g})",
f"{label} ({val:.3g})",
transform=ax.get_yaxis_transform(),
ha="right",
ha="left",
va="bottom",
fontsize=th.fs_annot,
color=col,
bbox={"facecolor": "white", "edgecolor": "none", "alpha": 0.85, "pad": 0.6},
zorder=2.5,
)

from .units import axis_label
Expand Down
Loading
Loading