Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created May 21, 2022 10:54
Show Gist options
  • Save jkrumbiegel/e8062ee6294c17b8ccf7abc0d98473b9 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/e8062ee6294c17b8ccf7abc0d98473b9 to your computer and use it in GitHub Desktop.
Makie 3D Barplot
@recipe(Barplot3D) do scene
Attributes(
color = theme(scene, :markercolor),
colormap = theme(scene, :colormap),
)
end
Makie.conversion_trait(::Type{<:Barplot3D}) = Makie.DiscreteSurface()
function Makie.plot!(p::Barplot3D)
x = @views (p[1][][1:end-1] .+ p[1][][2:end]) .* 0.5
y = @views (p[2][][1:end-1] .+ p[2][][2:end]) .* 0.5
widths_x = diff(p[1][])
widths_y = diff(p[2][])
heights = p[3][]
markersizes = vec(Vec3f.(widths_x, widths_y', heights))
meshscatter!(p, x, y, zeros(size(p[3][])),
marker = Rect3(Vec3f(-0.5, -0.5, 0), Vec3f(1)),
markersize = markersizes,
color = p.color,
colormap = p.colormap,
)
end
function Makie.data_limits(b::Barplot3D)
x = extrema(b[1][])
y = extrema(b[2][])
zmax = maximum(b[3][])
Rect3f((x[1], y[1], 0), (x[2]-x[1], y[2]-y[1], zmax))
end
z = abs.(randn(10, 10))
f, ax, b = barplot3d(1:10, 1:10, z,
axis = (type = Axis3, ),
color = vec(z),
colormap = :inferno,
)
zlims!(ax, low = 0)
f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment