Skip to content

feat!: Support matrix data with units#5623

Draft
icweaver wants to merge 4 commits into
MakieOrg:ff/breaking-0.25from
icweaver:units-matrix
Draft

feat!: Support matrix data with units#5623
icweaver wants to merge 4 commits into
MakieOrg:ff/breaking-0.25from
icweaver:units-matrix

Conversation

@icweaver
Copy link
Copy Markdown
Contributor

@icweaver icweaver commented May 6, 2026

Description

Follow-up to https://discourse.julialang.org/t/juliahub-raises-65m-series-b-and-launches-dyad-3-0/136941/20

Allows for things like this to work now:

using CairoMakie, DynamicQuantities

fig, ax, p = heatmap(rand(3, 4)u"kg")

Colorbar(fig[1, 2], p; label = "Mass")
Colorbar(fig[1, 3], p; label = "Mass", dim_convert = Makie.DQConversion(us"g"))
Colorbar(fig[1, 4], p; label = "Mass", label_suffix = "unit: ({})")

fig
display

Changes listed here: https://github.com/icweaver/Makie.jl/blob/units-matrix/CHANGELOG.md#unreleased

Would something like this make sense to add? At any rate, thanks all for the exciting developments that are going into v0.25 and beyond!

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Added an entry in CHANGELOG.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.
  • Implement format and use_short_units for DQ

@github-project-automation github-project-automation Bot moved this to Work in progress in PR review May 6, 2026
@icweaver icweaver changed the title Units matrix feat: Support matrix data with units May 6, 2026
@icweaver icweaver mentioned this pull request May 6, 2026
@icweaver icweaver changed the title feat: Support matrix data with units feat!: Support matrix data with units May 6, 2026
Comment on lines +91 to +93
argument_dims(::ImageLike, x, y, z) = (1, 2, 3)
argument_dims(::VertexGrid, x, y, z) = (1, 2, 3) # contour, contourf
argument_dims(::CellGrid, x, y, z) = (1, 2, 3)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, the heatmap/image/etc. data will be forced¹ to synchronize with other plots that map to dim 3. E.g. if you add a z component to scatter, that will have to synchronize. (You can use z values for ordering/layering in Axis.) Or if you plot multiple heatmaps.
Is that something we want? Or don't want? Or don't care about?

¹ Breaking also added force_dimconverts as a plot kwarg which can be set to false to allow unitless data to pass through. So it's not entirely forced, but still what happens by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, force_dimconverts is a really nice escape hatch:

fig = Figure()
ax = Axis3(fig[1, 1])

scatter!(ax, 1:3, 1:3, (4:6)u"cm")
heatmap!(ax, 1:3, 1:3, rand(3, 3); force_dimconverts = false)

fig

Would adding a unit-aware method for transform! be feasible too? Then, being able to do something like this seems intuitive to me:

 fig = Figure()
 ax = Axis3(fig[1, 1])

 scatter!(ax, 1:3, 1:3, (4:6)u"cm")
 heatmap!(ax, 1:3, 1:3, rand(3, 3); transformation = (:xy, 5u"cm"),  force_dimconverts = false)

 fig

I'm still exploring the internals, but it seems like more invasive changes would need to be made if we were to go with implementing a totally separate color dim convert instead of just re-using the machinery that's already in place, so I feel inclined to just stick with the above design decision and document the force_dimconverts option for folks that need it.

I rarely if ever work in 3D, so apologies if I am missing other common use cases where this might be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Work in progress

Development

Successfully merging this pull request may close these issues.

2 participants