I’m trying to add a colorbar to a 3D contour plot in GLMakie with the actual range of the function values. However, the colorbar I get only shows a range from 0 to 1, while the actual range is [-0.7, 0.7].
Here is the code I am using:
using GLMakie
x = LinRange(-1, 1, 20)
y = LinRange(-1, 1, 20)
z = LinRange(-1, 1, 20)
values = [sin(x[i]) * cos(y[j]) * sin(z[k]) for i in 1:20, j in 1:20, k in 1:20]
fig = Figure()
ax = Axis3(fig[1, 1], title="3D Contour Example")
contour!(ax, x, y, z, values, levels=10, colormap=:viridis)
fig[1, 2] = Colorbar(fig, label="Function Value")
display(fig)
The alternatives that I tried give errors. For example,
cf = contour!(ax, x, y, z, levels=50)
fig[1, 2] = Colorbar(fig, cf, label="Function Value")
ERROR: KeyError: key :highclip not found
Stacktrace:
[1] getindex(h::Dict{Symbol, Observable}, key::Symbol)
@ Base ./dict.jl:484
[2] getindex
@ ~/.julia/packages/MakieCore/zgrOY/src/attributes.jl:89 [inlined]
[3] getindex(x::Combined{Makie.contour, Tuple{LinRange{Float64, Int64}, LinRange{Float64, Int64}, LinRange{Float64, Int64}, Array{Float32, 3}}}, key::Symbol)
@ MakieCore ~/.julia/packages/MakieCore/zgrOY/src/attributes.jl:185
[4] getproperty(x::Combined{Makie.contour, Tuple{LinRange{Float64, Int64}, LinRange{Float64, Int64}, LinRange{Float64, Int64}, Array{Float32, 3}}}, key::Symbol)
@ MakieCore ~/.julia/packages/MakieCore/zgrOY/src/attributes.jl:76
[5] Colorbar(fig_or_scene::Figure, plot::Combined{Makie.contour, Tuple{LinRange{Float64, Int64}, LinRange{Float64, Int64}, LinRange{Float64, Int64}, Array{Float32, 3}}}; kwargs::Base.Pairs{Symbol, String, Tuple{Symbol}, NamedTuple{(:label,), Tuple{String}}})
@ Makie ~/.julia/packages/Makie/Ylh0P/src/makielayout/blocks/colorbar.jl:39
[6] top-level scope
… my stuff