Skip to content

Allow vector (or column) of symbols in mapping #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajinkya-k opened this issue Mar 26, 2025 · 1 comment
Closed

Allow vector (or column) of symbols in mapping #622

ajinkya-k opened this issue Mar 26, 2025 · 1 comment

Comments

@ajinkya-k
Copy link

Problem description

if an aesthetic like color is mapped to a vector of symbols AoG throws an error, but if the symbols are converted to strings the mapping works. Here is an example (original example is from user jar on the julialang slack which i modified to use AoG instead of raw makie):

this code chunk throws an error:

let n = 50,  x = randn(n), y = randn(n), c = rand((:a, :b, :c), n)
    draw(
        mapping(x, y, color = c) * visual(Scatter),
        scales(Color = (; palette = from_continuous(Makie.wong_colors())))
    )
end
click triangle to see error ``` ERROR: MethodError: no method matching length(::Symbol) The function `length` exists, but no method is defined for this combination of argument types.

Closest candidates are:
length(::LaTeXStrings.LaTeXString)
@ LaTeXStrings ~/.julia/packages/LaTeXStrings/6NrIG/src/LaTeXStrings.jl:112
length(::Distributions.DirichletStats)
@ Distributions ~/.julia/packages/Distributions/fi8Qd/src/multivariate/dirichlet.jl:186
length(::VSCodeServer.JSON.Parser.MemoryParserState)
@ VSCodeServer ~/.vscode-oss/extensions/julialang.language-julia-1.127.2-universal/scripts/packages/JSON/src/Parser.jl:29
...

Stacktrace:
[1] length(g::Base.Generator{Symbol, typeof(identity)})
@ Base ./generator.jl:51
[2] _similar_shape(itr::Base.Generator{Symbol, typeof(identity)}, ::Base.HasLength)
@ Base ./array.jl:663
[3] collect(itr::Base.Generator{Symbol, typeof(identity)})
@ Base ./array.jl:790
[4] map(f::Function, A::Symbol)
@ Base ./abstractarray.jl:3399
[5] (::AlgebraOfGraphics.var"#195#200")(x::Tuple{Symbol})
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/processing.jl:85
[6] iterate
@ ./generator.jl:48 [inlined]
[7] collect(itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{Symbol}}}, AlgebraOfGraphics.var"#195#200"})
@ Base ./array.jl:791
[8] map(f::Function, A::Base.Iterators.Zip{Tuple{Vector{Symbol}}})
@ Base ./abstractarray.jl:3399
[9] getlabeledarray(layer::Layer, s::Vector{Symbol})
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/processing.jl:85
[10] (::AlgebraOfGraphics.var"#211#217"{Layer})(v::Vector{Symbol})
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/processing.jl:133
[11] map!(f::AlgebraOfGraphics.var"#211#217"{…}, out::Dictionaries.Dictionary{…}, d::Dictionaries.Dictionary{…})
@ Dictionaries ~/.julia/packages/Dictionaries/tq7Jt/src/map.jl:57
[12] map
@ ~/.julia/packages/Dictionaries/tq7Jt/src/map.jl:92 [inlined]
[13] process_mappings(layer::Layer)
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/processing.jl:133
[14] process(layer::Layer)
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/processing.jl:162
[15] ProcessedLayers
@ ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/layers.jl:68 [inlined]
[16] compute_axes_grid(d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/layers.jl:263
[17] compute_axes_grid
@ ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/algebra/layers.jl:261 [inlined]
[18] _draw(d::Layer, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{…}, figure::Dictionaries.Dictionary{…}, facet::Dictionaries.Dictionary{…}, legend::Dictionaries.Dictionary{…}, colorbar::Dictionaries.Dictionary{…})
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/draw.jl:157
[19] _draw
@ ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/draw.jl:154 [inlined]
[20] draw(d::Layer, scales::AlgebraOfGraphics.Scales; axis::@NamedTuple{}, figure::@NamedTuple{}, facet::@NamedTuple{}, legend::@NamedTuple{}, colorbar::@NamedTuple{}, palette::Nothing)
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/draw.jl:85
[21] draw(d::Layer, scales::AlgebraOfGraphics.Scales)
@ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/a4FNT/src/draw.jl:75
[22] top-level scope
@ Untitled-1:20

</details>

but the following works: 

let n = 50, x = randn(n), y = randn(n), c = rand((:a, :b, :c), n)
draw(
mapping(x, y, color = String.(c)) * visual(Scatter),
scales(Color = (; palette = from_continuous(Makie.wong_colors())))
)
end

@jkrumbiegel
Copy link
Member

fixed by #651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants