Skip to content

Plot unions, unit simplices and unit cubes with Makie, and unions with Plots - #187

Merged
dlfivefifty merged 4 commits into
masterfrom
makie-unions-simplices
Sep 28, 2026
Merged

dlfivefifty merged 4 commits into
masterfrom
makie-unions-simplices

Conversation

@dlfivefifty

@dlfivefifty dlfivefifty commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Extends DomainSetsMakieExt to plot more domains:

  • Unions: a UnionDomain is plotted by plotting each component in one colour, with colours cycling between unions. Components are plotted with their usual plot types and may be different kinds of domains, e.g. a disk and a rectangle.
  • Unit simplices: UnitSimplex is a filled triangle in 2D and a tetrahedron mesh in 3D. Other dimensions throw an ArgumentError.
  • Unit cubes: UnitSquare() and UnitCube() used to throw a MethodError, because the conversion to a Makie rectangle only handled Rectangle{<:SVector}. It now uses infimum/supremum, which every HyperRectangle supports.
using DomainSets, StaticArrays, CairoMakie
fig, ax, _ = plot(UnionDomain(UnitDisk(), Ball(0.5, SVector(2.5, 0.0))))
plot!(ax, UnitSimplex(Val(2)))
plot!(ax, UnitSquare())

Plots: a new DomainSetsRecipesBaseExt plots a UnionDomain with Plots by emitting each component as its own series. Only the first component is primary, so the others reuse its colour and get no legend entry. This makes, e.g., plot(domain(G)) work in Plots for a contour made of segments, with each segment drawn by its own recipe. For the whole union to be one colour, the component recipes must not force primary := true; the IntervalSets and RiemannHilbert recipes currently do, and would need primary --> true. Tests use RecipesBase.apply_recipe, so Plots isn't a test dependency.

Unions of intervals, e.g. UnionDomain(0..1, 2..3), also work once JuliaMath/IntervalSets.jl#224 is released. That PR adds a Makie recipe for intervals, and the union recipe plots each interval with it. The corresponding test only runs when that extension is loaded.

Compat: the union recipe uses the current @recipe syntax, so the Makie compat is now 0.21, 0.22, 0.23, 0.24, dropping 0.19 and 0.20. Users on those versions stay on the current release. On Makie < 0.24, colours only cycle between unions whose components have the same types, because the cycler is keyed by the concrete plot type.

A small inconsistency: union pieces use the line colour palette, so a union of disks is fully opaque, whereas a single disk uses Makie's slightly transparent polygon palette. Matching them would mean choosing the palette per component type; happy to do that if you'd like.

Hash fix (separate commit): in Julia ≥ 1.13, hash(x) uses a non-zero default seed (Base.HASH_SEED). So the one-argument domainhash(d), which used seed zero, no longer matched hash(d). Eight level set and indicator function tests failed, and because each test file is a top-level testset, the run stopped before the extension tests. domainhash(d) now uses the same seed as hash(d).

Testing:

  • The full test suite passes on Julia 1.13 and 1.10 (rechecked on 1.13 with the RecipesBase extension).
  • The Makie tests pass on Makie 0.21 and 0.24.
  • I checked the plots visually with CairoMakie.

Bumps the version to v0.8.3.

🤖 Generated with Claude Code

dlfivefifty and others added 2 commits September 28, 2026 09:10
In Julia ≥ 1.13, `hash(x)` uses a nonzero default seed (`Base.HASH_SEED`),
so `domainhash(d)` with a zero seed no longer agreed with `hash(d)` and
the level set and indicator function hash tests failed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- a UnionDomain is plotted by plotting each component in one color, with
  colors cycling between unions
- UnitSimplex is a triangle in 2D and a tetrahedron in 3D
- converting a HyperRectangle uses infimum/supremum, so UnitSquare() and
  UnitCube() no longer error

The union recipe uses the current @recipe syntax, so the Makie compat is
now 0.21-0.24.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.04%. Comparing base (0523e1d) to head (b21a407).

Files with missing lines Patch % Lines
ext/DomainSetsRecipesBaseExt.jl 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #187      +/-   ##
==========================================
+ Coverage   93.93%   94.04%   +0.11%     
==========================================
  Files          27       28       +1     
  Lines        1846     1865      +19     
==========================================
+ Hits         1734     1754      +20     
+ Misses        112      111       -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dlfivefifty and others added 2 commits September 28, 2026 16:05
…docs

Without backticks, Documenter looked for headers with these names instead
of the docstrings, and the docs build failed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A UnionDomain is plotted by plotting each of its components as a series,
with only the first having a legend entry, so that e.g. a contour made of
segments or a union of intervals can be plotted with `plot(d)`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@dlfivefifty dlfivefifty changed the title Plot unions, unit simplices and unit cubes with Makie Plot unions, unit simplices and unit cubes with Makie, and unions with Plots Sep 28, 2026
@dlfivefifty
dlfivefifty merged commit ad941e6 into master Sep 28, 2026
7 checks passed
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.

1 participant