Skip to content

Instantly share code, notes, and snippets.

@mforets
Created April 21, 2021 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mforets/e219588cf406b7eecb5ec920ad380a0a to your computer and use it in GitHub Desktop.
Save mforets/e219588cf406b7eecb5ec920ad380a0a to your computer and use it in GitHub Desktop.
Hyperrectangle plots with Makie
### Code
```julia
function makie_3d_plot(scene, data::Vector{IntervalBox{3, N}}, color=nothing) where N
# plotting a single box in 3D doesn't work as expected
@assert length(data) > 1
positions = [Point3f0(mid(X)) for X in data]
scales = [Vec3f0(diam.(X)) for X in data]
local colors
if color == nothing
xs = Float32[x[1] for x in positions]
ys = Float32[x[2] for x in positions]
zs = Float32[x[3] for x in positions]
minx, maxx = extrema(xs)
miny, maxy = extrema(ys)
minz, maxz = extrema(zs)
colors = RGBA{Float32}[
RGBA( (xs[i] - minx) / (maxx - minx),
(ys[i] - miny) / (maxy - miny),
(zs[i] - minz) / (maxz - minz),
0.5f0 )
for i in 1:length(data)
];
else
colors = [color for X in data]
end
## Makie plotting:
# centre widths
#cube = Rect3D(Vec3f0(-0.5, -0.5, -0.5), Vec3f0(1, 1, 1))
cube = Rect3D(Vec3f0(0.0, 0.0, 0.0), Vec3f0(5., 5., 5.))
Makie.meshscatter!(scene, positions, marker=cube, scales=scales, color=colors, transparency=true)
end
```
### Example use:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment