AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
Cannot use alpha with numeric color mapping
The following works fine:
df = (x=1:3, y=1:3, c=1:3)
plt = data(df) * mapping(:x, :y, color=:c => nonnumeric) * visual(alpha=0.5)
draw(plt)
but if I remove the nonnumeric I get MethodError: no method matching color(::Vector{Int64}).
I guess this will be fixed at the same time as #225, but in the meantime it would be nice to have a workaround, so that alpha can be used with continous color scales...
Stack trace
MethodError: no method matching color(::Vector{Int64})
Closest candidates are:
color(::ColorTypes.Color) at ~/.julia/packages/ColorTypes/6m8P7/src/traits.jl:108
color(::ColorTypes.TransparentColor{C, T, 2} where T) where C at ~/.julia/packages/ColorTypes/6m8P7/src/traits.jl:109
color(::ColorTypes.TransparentColor{C, T, 3} where T) where C at ~/.julia/packages/ColorTypes/6m8P7/src/traits.jl:110
...
Stacktrace:
[1] convert_attribute(c::Tuple{Vector{Int64}, Float64}, k::MakieCore.Key{:color})
@ Makie ~/.julia/packages/Makie/vwpRo/src/conversions.jl:771
[2] get_attribute(dict::Scatter{Tuple{Vector{Point{2, Float32}}}}, key::Symbol)
@ MakieCore ~/.julia/packages/MakieCore/A0hGm/src/attributes.jl:242
[3] draw_atomic(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Scatter{Tuple{Vector{Point{2, Float32}}}})
@ CairoMakie ~/.julia/packages/CairoMakie/JAJ5G/src/primitives.jl:176
[4] draw_plot(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Scatter{Tuple{Vector{Point{2, Float32}}}})
@ CairoMakie ~/.julia/packages/CairoMakie/JAJ5G/src/infrastructure.jl:230
[5] cairo_draw(screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/JAJ5G/src/infrastructure.jl:172
[6] backend_show(x::CairoMakie.CairoBackend, io::IOContext{Base64.Base64EncodePipe}, #unused#::MIME{Symbol("image/png")}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/JAJ5G/src/infrastructure.jl:335
[7] show(io::IOContext{Base64.Base64EncodePipe}, m::MIME{Symbol("image/png")}, scene::Scene)
@ Makie ~/.julia/packages/Makie/vwpRo/src/display.jl:109
[8] #show#920
@ ~/.julia/packages/Makie/vwpRo/src/display.jl:103 [inlined]
[9] show
@ ~/.julia/packages/Makie/vwpRo/src/display.jl:103 [inlined]
[10] show
@ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/entries.jl:89 [inlined]
[11] limitstringmime(mime::MIME{Symbol("image/png")}, x::AlgebraOfGraphics.FigureGrid)
@ IJulia ~/.julia/packages/IJulia/e8kqU/src/inline.jl:50
[12] display_mimestring
@ ~/.julia/packages/IJulia/e8kqU/src/display.jl:67 [inlined]
[13] display_dict(f::AlgebraOfGraphics.FigureGrid)
@ Main ./In[76]:2
[14] #invokelatest#2
@ ./essentials.jl:716 [inlined]
[15] invokelatest
@ ./essentials.jl:714 [inlined]
[16] execute_request(socket::ZMQ.Socket, msg::IJulia.Msg)
@ IJulia ~/.julia/packages/IJulia/e8kqU/src/execute_request.jl:112
[17] #invokelatest#2
@ ./essentials.jl:716 [inlined]
[18] invokelatest
@ ./essentials.jl:714 [inlined]
[19] eventloop(socket::ZMQ.Socket)
@ IJulia ~/.julia/packages/IJulia/e8kqU/src/eventloop.jl:8
[20] (::IJulia.var"#15#18")()
@ IJulia ./task.jl:423
Tested with AlgebraOfGraphics 0.6.5 and Makie 0.16.5.
This will be slightly trickier to solve in a clean way. Makie support alpha transparency for continuous color directly in the colormap attribute, so visual(colormap=(:batlow, 0.5)) should work. It should be feasible to get this to work by default.
Thanks for the workaround with colormap! Though it's annoying in my case that the colorbar is also affected:
df = (x=vec((1:3) .+ rand(200)'),
y=vec((1:3) .+ rand(200)'),
c=vec([1,2,5] .+ rand(200)'))
plt = data(df) * mapping(:x, :y, color=:c) * visual(colormap=(:viridis, 0.3))
draw(plt, axis=(width=300, height=200))

@knuesel Have you since figured out a way to prevent the colorbar from being affected? I'm trying a similar plot.
@czimm79 no for now I'm just not using transparency in those plots with continuous color scale.
just to say the original example works for me now; I'm on
AlgebraOfGraphics v0.6.12
CairoMakie v0.9.4
Makie v0.18.4
I still get an error on
AlgebraOfGraphics v0.6.16
CairoMakie v0.10.6
Makie v0.19.6
@ericphanson are you sure you removed nonnumeric from the example code?
Oh oops, no I just copied the example code as-is. I must've misread, sorry.