diff --git a/src/interaction/inspector.jl b/src/interaction/inspector.jl index 393d91f6fc1..0fce5bbe703 100644 --- a/src/interaction/inspector.jl +++ b/src/interaction/inspector.jl @@ -662,7 +662,7 @@ function show_imagelike(inspector, plot, name, edge_based) a._color[] = if z isa AbstractFloat interpolated_getindex( to_colormap(plot.colormap[]), z, - to_value(get(plot.attributes, :colorrange, (0, 1))) + extract_colorrange(plot) ) else z diff --git a/src/makielayout/blocks/colorbar.jl b/src/makielayout/blocks/colorbar.jl index 1330308e364..ca2fb97da30 100644 --- a/src/makielayout/blocks/colorbar.jl +++ b/src/makielayout/blocks/colorbar.jl @@ -25,6 +25,16 @@ function colorbar_check(keys, kwargs_keys) end end +function extract_colorrange(@nospecialize(plot::AbstractPlot))::Vec2{Float64} + if haskey(plot, :calculated_colors) && plot.calculated_colors[] isa Makie.ColorMapping + return plot.calculated_colors[].colorrange[] + elseif haskey(plot, :colorrange) && !(plot.colorrange[] isa Makie.Automatic) + return plot.colorrange[] + else + error("colorrange not found and calculated_colors for the plot is missing or is not a proper color map. Heatmaps and images should always contain calculated_colors[].colorrange") + end +end + function extract_colormap(@nospecialize(plot::AbstractPlot)) has_colorrange = haskey(plot, :colorrange) && !(plot.colorrange[] isa Makie.Automatic) if haskey(plot, :calculated_colors) && plot.calculated_colors[] isa Makie.ColorMapping