Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created December 19, 2023 10:46
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 jkrumbiegel/9d0b19a8d39175da0a2d088e837bb40f to your computer and use it in GitHub Desktop.
Save jkrumbiegel/9d0b19a8d39175da0a2d088e837bb40f to your computer and use it in GitHub Desktop.
Stepped contourf volcano plot in Makie
using GLMakie
using DelimitedFiles
volcano = readdlm(Makie.assetpath("volcano.csv"), ',', Float64)
_, _, ct = contourf(volcano; colormap = :lipari, levels = 20)
polys = ct.plots[1][1][]
level_values = ct.plots[1].color[]
level_indices = let
i = 0
prev = nothing
indices = Int[]
for val in level_values
if val != prev
i += 1
end
push!(indices, i)
prev = val
end
indices
end
colors = Makie.numbers_to_colors(ct.plots[1].color[], ct.plots[1])
f = Figure()
ax3 = Axis3(f[1, 1])
for (i, (poly, index)) in enumerate(zip(polys, level_indices))
points = decompose(Point2f, poly.exterior)
points_top = [Point3f(p..., index) for p in points]
points_bottom = [Point3f(p..., index-1) for p in points]
p = poly!(ax3, points, color = colors[i])
Makie.transform!(p, (:xy, index))
band!(ax3, points_bottom, points_top, color = colors[i], shading = MultiLightShading)
end
f
@jkrumbiegel
Copy link
Author

grafik

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