Skip to content

FIX: Space automatic contour levels logarithmically under a log norm - #168

Merged
thclark merged 1 commit into
bars-and-histogramsfrom
log-contour-levels
Oct 26, 2026
Merged

thclark merged 1 commit into
bars-and-histogramsfrom
log-contour-levels

Conversation

@thclark

@thclark thclark commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Automatic contour levels are now spaced logarithmically when a contour's colour scale has a logarithmic norm. The fix ships with the bars and histograms release (0.16.0), so this PR targets the epic trunk. The patch bump to 0.15.1 that it carried for a release from main has been dropped.

Before and after

Before, contour_levels in crates/ironlab-scene/src/compile/artists.rs always placed linear levels. A field spanning several decades therefore had all its isolines in its top decade. In the issue's reproduction, the levels were 100, 200, …, 900.

Under a logarithmic norm, Levels::Auto, and a contour with no levels of its own on a continuous scale, now choose levels strictly inside the range of the field's positive values. They are chosen in this order:

  1. the decades, thinned to at most the requested count;
  2. if fewer than two decades lie inside the range, 1, 2 and 5 times each decade;
  3. failing that, 1 to 9 times each decade;
  4. failing that, linear levels.

The reproduction now draws isolines at 0.1, 1, 10 and 100.

Band colours

A filled band under a logarithmic norm now takes the colour of its geometric middle, rather than its arithmetic middle, so that it matches its place on the colourbar.

Unchanged and documented

A discrete scale's band edges are unchanged. The contour section of the figure schema reference documents the new levels.

Closes #167

Automatic contour levels were always spaced linearly, so a field spanning
several decades seen through a colour scale with a logarithmic norm had all
its isolines in its top decade, in nearly one colour.

Under a logarithmic norm, automatic levels are now chosen strictly inside the
range of the positive values of the field, as Matplotlib's LogLocator places
them: the decades, thinned to at most the requested count; failing two
decades, 1, 2 and 5 times each decade; then 1 to 9 times each decade; then
linear levels. A filled band under a logarithmic norm is coloured by its
geometric middle, so that its colour matches the middle of its span on the
bar. Band edges supplied by a discrete scale are unaffected.

Closes #167
@thclark
thclark force-pushed the log-contour-levels branch from 4979077 to d04cb28 Compare October 26, 2026 12:42
@thclark
thclark changed the base branch from main to bars-and-histograms October 26, 2026 12:42
@thclark
thclark merged commit dd6b3f0 into bars-and-histograms Oct 26, 2026
8 checks passed
thclark added a commit that referenced this pull request Oct 26, 2026
…168)

Automatic contour levels were always spaced linearly, so a field spanning
several decades seen through a colour scale with a logarithmic norm had all
its isolines in its top decade, in nearly one colour.

Under a logarithmic norm, automatic levels are now chosen strictly inside the
range of the positive values of the field, as Matplotlib's LogLocator places
them: the decades, thinned to at most the requested count; failing two
decades, 1, 2 and 5 times each decade; then 1 to 9 times each decade; then
linear levels. A filled band under a logarithmic norm is coloured by its
geometric middle, so that its colour matches the middle of its span on the
bar. Band edges supplied by a discrete scale are unaffected.

Closes #167
@thclark
thclark deleted the log-contour-levels branch October 26, 2026 14:41
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.

Space automatic contour levels logarithmically on a logarithmic colour scale

1 participant