DimensionalData.jl
DimensionalData.jl copied to clipboard
Support plot mutation with global Axis
As described in https://github.com/rafaqz/DimensionalData.jl/pull/712#issuecomment-2117150302, plot mutation is no longer supported. i.e.
using DimensionalData, CairoMakie
A = rand(X(10:10:100), Y([:a, :b, :c]))
f = Figure(); ax = Axis(f[1,1])
Makie.plot!(A; colormap=:inferno)
f
Stacktrace
ERROR: MethodError: Cannot `convert` an object of type
DimMatrix{ColorTypes.RGBA{Float32}, Tuple{X{DimensionalData.Dimensions.Lookups.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata}}, Y{DimensionalData.Dimensions.Lookups.Categorical{Symbol, Vector{Symbol}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.NoMetadata}}}, Tuple{}, Matrix{ColorTypes.RGBA{Float32}}, DimensionalData.NoName, DimensionalData.Dimensions.Lookups.NoMetadata} to an object of type
Union{ColorTypes.RGBA{Float32}, Matrix{ColorTypes.RGBA{Float32}}}
Closest candidates are:
convert(::Type{T}, ::T) where T
@ Base Base.jl:84
Stacktrace:
[1] numbers_to_colors(numbers::DimMatrix{Float32, Tuple{X{DimensionalData.Dimensions.Lookups.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata}}, Y{DimensionalData.Dimensions.Lookups.Categorical{Symbol, Vector{Symbol}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.NoMetadata}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.Lookups.NoMetadata}, colormap::Vector{ColorTypes.RGBA{Float32}}, colorscale::Function, colorrange::Vec{2, Float32}, lowclip::ColorTypes.RGBA{Float32}, highclip::ColorTypes.RGBA{Float32}, nan_color::ColorTypes.RGBA{Float32})
@ Makie ~/.julia/packages/Makie/We6MY/src/colorsampler.jl:163
[2] to_color(c::Makie.ColorMapping{2, DimMatrix{Float32, Tuple{X{DimensionalData.Dimensions.Lookups.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata}}, Y{DimensionalData.Dimensions.Lookups.Categorical{Symbol, Vector{Symbol}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.NoMetadata}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.Lookups.NoMetadata}, DimMatrix{Float32, Tuple{X{DimensionalData.Dimensions.Lookups.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata}}, Y{DimensionalData.Dimensions.Lookups.Categorical{Symbol, Vector{Symbol}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.NoMetadata}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.Lookups.NoMetadata}})
@ Makie ~/.julia/packages/Makie/We6MY/src/colorsampler.jl:346
[3] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Union{Image, Heatmap})
@ CairoMakie ~/.julia/packages/CairoMakie/fZ4Q9/src/primitives.jl:849
[4] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Heatmap{Tuple{Vector{Float32}, Vector{Float32}, DimMatrix{Float32, Tuple{X{DimensionalData.Dimensions.Lookups.Sampled{Int64, StepRange{Int64, Int64}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.Regular{Int64}, DimensionalData.Dimensions.Lookups.Points, DimensionalData.Dimensions.Lookups.NoMetadata}}, Y{DimensionalData.Dimensions.Lookups.Categorical{Symbol, Vector{Symbol}, DimensionalData.Dimensions.Lookups.ForwardOrdered, DimensionalData.Dimensions.Lookups.NoMetadata}}}, Tuple{}, Matrix{Float32}, DimensionalData.NoName, DimensionalData.Dimensions.Lookups.NoMetadata}}})
@ CairoMakie ~/.julia/packages/CairoMakie/fZ4Q9/src/infrastructure.jl:129
[5] cairo_draw(screen::CairoMakie.Screen{CairoMakie.IMAGE}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/fZ4Q9/src/infrastructure.jl:51
[6] backend_show(screen::CairoMakie.Screen{CairoMakie.IMAGE}, io::IOBuffer, ::MIME{Symbol("image/png")}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/fZ4Q9/src/display.jl:104
[7] backend_show(screen::CairoMakie.Screen{CairoMakie.IMAGE}, io::IOBuffer, ::MIME{Symbol("juliavscode/html")}, scene::Scene)
@ Makie ~/.julia/packages/Makie/We6MY/src/display.jl:490
[8] show(io::IOBuffer, m::MIME{Symbol("juliavscode/html")}, figlike::Figure)
@ Makie ~/.julia/packages/Makie/We6MY/src/display.jl:259
[9] __binrepr(m::MIME{Symbol("juliavscode/html")}, x::Figure, context::Nothing)
@ Base.Multimedia ./multimedia.jl:171
[10] _textrepr
@ ./multimedia.jl:163 [inlined]
[11] repr(m::MIME{Symbol("juliavscode/html")}, x::Figure)
@ Base.Multimedia ./multimedia.jl:159
[12] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("juliavscode/html")}, x::Any)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/display.jl:68
[13] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
@ Base.Multimedia ./multimedia.jl:228
[14] display(d::VSCodeServer.InlineDisplay, x::Any)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/display.jl:207
[15] display(x::Any)
@ Base.Multimedia ./multimedia.jl:340
[16] display(figlike::Figure; backend::Module, inline::MakieCore.Automatic, update::Bool, screen_config::@Kwargs{})
@ Makie ~/.julia/packages/Makie/We6MY/src/display.jl:150
[17] display(figlike::Figure)
@ Makie ~/.julia/packages/Makie/We6MY/src/display.jl:130
[18] #invokelatest#2
@ ./essentials.jl:892 [inlined]
[19] invokelatest
@ ./essentials.jl:889 [inlined]
[20] (::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/eval.jl:237
[21] withpath(f::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/repl.jl:276
[22] (::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/eval.jl:179
[23] hideprompt(f::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/repl.jl:38
[24] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/eval.jl:150
[25] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging ./logging.jl:515
[26] with_logger
@ ./logging.jl:627 [inlined]
[27] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/eval.jl:263
[28] #invokelatest#2
@ ./essentials.jl:892 [inlined]
[29] invokelatest(::Any)
@ Base ./essentials.jl:889
[30] (::VSCodeServer.var"#64#65")()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.79.2/scripts/packages/VSCodeServer/src/eval.jl:34
julia> using Pkg; Pkg.status()
Status `~/src/sandbox/2024/bug_makie_dd/Project.toml`
[13f3f980] CairoMakie v0.12.2
[0703355e] DimensionalData v0.27.3
[ee78f7c6] Makie v0.21.2
No that syntax was never supported here, as Makie isn't really set up to do it yet.
Basically you always have to use the ax first argument:
Makie.plot!(ax, A; colormap=:inferno)
(if you can figure out how to fix it, go for it...)
I'm a bit embarrassed; sorry for using up your time on this!
No worries, I make that mistake all the time too
And seriously, there must be a way to fix it, I just don't know the Makie internals for that well enough
Shouldnt defining plottype(::DimensionalArray}) just work?
No idea ;)
No that syntax was never supported here, as Makie isn't really set up to do it yet.
Basically you always have to use the
axfirst argument:Makie.plot!(ax, A; colormap=:inferno)(if you can figure out how to fix it, go for it...)
That is not true, it works in GLMakie as expected and I can reproduce the error in CairoMakie.
Hm it could partly work I guess just with the defaults
I also suspect, that this is something that changed with Makie 0.21 because with Makie 0.20 I get a different error about symbol handling with the provided DimArray, but when I change the Y axis to have integer values the plot! works without the axis.
Ah we probably need to define expand_dimensions then
Interestingly the mutation on global Axis works for a DimArray with a Unitful axis but fails with Symbol axis. I am exploring this in #957
Paste errors if you can
This is the current error for a two dimensional DimArray with a Symbol Axis:
julia> Makie.plot!(A; colormap=:inferno)
ERROR: MethodError: no method matching zero(::Symbol)
The function `zero` exists, but no method is defined for this combination of argument types.
Closest candidates are:
zero(::Type{Union{}}, Any...)
@ Base number.jl:310
zero(::Type{LibGit2.GitHash})
@ LibGit2 ~/.julia/juliaup/julia-1.11.4+0.x64.linux.gnu/share/julia/stdlib/v1.11/LibGit2/src/oid.jl:221
zero(::Type{Pkg.Resolve.VersionWeight})
@ Pkg ~/.julia/juliaup/julia-1.11.4+0.x64.linux.gnu/share/julia/stdlib/v1.11/Pkg/src/Resolve/versionweights.jl:15
...
Stacktrace:
[1] LinRange(start::Symbol, stop::Symbol, len::Int64)
@ Base ./range.jl:590
[2] range_start_stop_length(start::Symbol, stop::Symbol, len::Int64)
@ Base ./range.jl:596
[3] _range(start::Symbol, step::Nothing, stop::Symbol, len::Int64)
@ Base ./range.jl:167
[4] range(start::Symbol; stop::Symbol, length::Int64, step::Nothing)
@ Base ./range.jl:148
[5] to_linspace(x::Vector{Symbol}, N::Int64)
@ Makie ~/.julia/packages/Makie/Y3ABD/src/conversions.jl:705
[6] convert_arguments(P::CellGrid, x::Vector{Int64}, y::Vector{Symbol}, z::Matrix{Float32})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/conversions.jl:361
[7] convert_arguments(::Type{Heatmap}, ::Vector{Int64}, ::Vararg{Any}; kw::@Kwargs{})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/conversions.jl:26
[8] convert_arguments(::Type{Heatmap}, ::Vector{Int64}, ::Vector{Symbol}, ::Matrix{Float32})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/conversions.jl:14
[9] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, kw_obs::Observable{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
@ Makie ~/.julia/packages/Makie/Y3ABD/src/interfaces.jl:227
[10] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, kw_obs::Observable{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/interfaces.jl:218
[11] (Heatmap)(user_args::Tuple{DimMatrix{…}}, user_attributes::Dict{Symbol, Any})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/interfaces.jl:278
[12] _create_plot!(F::Function, attributes::Dict{…}, args::DimMatrix{…})
@ Makie ~/.julia/packages/Makie/Y3ABD/src/figureplotting.jl:377
[13] plot!(args::DimMatrix{…}; kw::@Kwargs{…})
@ MakieCore ~/.julia/packages/MakieCore/EU17Y/src/recipes.jl:59
[14] top-level scope
@ REPL[45]:1
Some type information was truncated. Use `show(err)` to see complete types.
This works now thanks to #1012