I have a question about why the approach to making a supertitle and updating it works in the first instance with the volume plots, but not in the second instance with the heatmaps?
In both cases, I create the new fig[0,:]
axis implicitly and set a LaTeXString
for it. For the volume plot it works beautifully, both at creation and for updating, while for the heatmaps it crashes with something inscrutable (hidden below for clarity). To be clear, the actual field rendering using volume
and heatmap
are correct and update correctly (data load / reassignment omitted), it’s just the ways in which labels and titles interact with the figures.
Bonus points if you know why the ternary operator for generating LaTeXString
s xlabel
s only on the last row of the heatmap axes does not work. It seems very strange.
Original code:
using GLMakie
times = 0:100
x = rand(Float32,200,200,50,3);
U = Observable(x[:,:,:,1])
V = Observable(x[:,:,:,2])
W = Observable(x[:,:,:,3])
fig = Figure(resolution = (1600, 600))
axs = [Axis3(fig[1,i], aspect=:data, elevation=0.75, azimuth=2.65, perspectiveness=0.2) for i in 1:3]
volume!(axs[1],U,algorithm=:mip,colormap="Oranges",alpha=0.05,transparence=true)
volume!(axs[2],V,algorithm=:mip,colormap="Purples",alpha=0.05,transparence=true)
volume!(axs[3],W,algorithm=:mip,colormap="Greens",alpha=0.05,transparence=true)
for ax in axs
hidedecorations!(ax)
end
Colorbar(fig[2,1]; vertical = false, flipaxis = false, colorrange=(0,1), colormap="Oranges", label=L"$u$")
Colorbar(fig[2,2]; vertical = false, flipaxis = false, colorrange=(0,1), colormap="Purples", label=L"$v$")
Colorbar(fig[2,3]; vertical = false, flipaxis = false, colorrange=(0,1), colormap="Greens", label=L"$w$")
tit = Label(fig[0, :], text = L"$t = 0$ [ms]", textsize = 32)
resize_to_layout!(fig)
record(fig, "./volumeMakie.mp4", times; framerate=20) do t
# update data here
tit.text[] = L"$t = %$(2.0*t)$ [ms]"
end
Zs = [1,10,20,30,40,50]
us = [Observable(x[:,:,z,1]) for z in Zs]
vs = [Observable(x[:,:,z,2]) for z in Zs]
ws = [Observable(x[:,:,z,3]) for z in Zs]
fig = Figure(resolution = (1450, 750))
axs = [ Axis3(fig[i, j], width = 200, height = 200, #=xlabel=(i==3 ? L"$z = Zs[j]*0.02$ [cm]" : nothing =#) for i in 1:3, j in 1:length(Zs) ]
for ax in axs
hidedecorations!(ax)
end
for j in 1:length(Zs)
heatmap!(axs[1,j],us[j],colormap="Oranges",colorrange=(0,1))
heatmap!(axs[2,j],vs[j],colormap="Purples",colorrange=(0,1))
heatmap!(axs[3,j],ws[j],colormap="Greens", colorrange=(0,1))
end
Colorbar(fig[1,length(Zs)+1]; colorrange=(0,1), colormap="Oranges", label=L"u")
Colorbar(fig[2,length(Zs)+1]; colorrange=(0,1), colormap="Purples", label=L"v")
Colorbar(fig[3,length(Zs)+1]; colorrange=(0,1), colormap="Greens", label=L"w")
tit = Label(fig[0,:], text = L"$t = 0$ [ms]", textsize = 32)
resize_to_layout!(fig)
record(fig, "heatmapsMakie.mp4", times; framerate=10) do t
# update data here
tit.text[] = L"$t = %$(2.0*t)$ [ms]"
end
Error:
ERROR: BoundsError: attempt to access 4-element Vector{Float32} at index [0]
Stacktrace:
[1] getindex
@ ./array.jl:861 [inlined]
[2] dirgaps(gl::GridLayout, dir::GridLayoutBase.Row)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:1008
[3] determinedirsize(gl::GridLayout, gdir::GridLayoutBase.Row)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:1041
[4] update!(gl::GridLayout)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:128
[5] add_to_gridlayout!
@ ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:229 [inlined]
[6] add_content!(g::GridLayout, content::Label, rows::UnitRange{Int64}, cols::UnitRange{Int64}, side::GridLayoutBase.Inner)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:1454
[7] setindex!(g::GridLayout, content::Label, rows::UnitRange{Int64}, cols::UnitRange{Int64}, side::GridLayoutBase.Inner)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:1341
[8] setindex!(gp::GridPosition, element::Label)
@ GridLayoutBase ~/.julia/packages/GridLayoutBase/ZQ2p1/src/gridlayout.jl:1487
[9] _block(::Type{Label}, ::GridPosition; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:text, :textsize), Tuple{LaTeXStrings.LaTeXString, Int64}}})
@ Makie.MakieLayout ~/.julia/packages/Makie/fEZv2/src/makielayout/blocks.jl:284
[10] #_#38
@ ~/.julia/packages/Makie/fEZv2/src/makielayout/blocks.jl:269 [inlined]
[11] top-level scope
@ REPL[29]:1