Created
April 21, 2021 20:07
-
-
Save mforets/e219588cf406b7eecb5ec920ad380a0a to your computer and use it in GitHub Desktop.
Hyperrectangle plots with Makie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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