Skip to content
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

Cannot use alpha with numeric color mapping #371

Open
knuesel opened this issue Mar 15, 2022 · 7 comments
Open

Cannot use alpha with numeric color mapping #371

knuesel opened this issue Mar 15, 2022 · 7 comments

Comments

@knuesel
Copy link
Contributor

knuesel commented Mar 15, 2022

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.

@piever
Copy link
Collaborator

piever commented Mar 15, 2022

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.

@knuesel
Copy link
Contributor Author

knuesel commented Mar 15, 2022

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))

image

@czimm79
Copy link

czimm79 commented Jun 7, 2022

@knuesel Have you since figured out a way to prevent the colorbar from being affected? I'm trying a similar plot.

@knuesel
Copy link
Contributor Author

knuesel commented Jun 14, 2022

@czimm79 no for now I'm just not using transparency in those plots with continuous color scale.

@ericphanson
Copy link

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

@knuesel
Copy link
Contributor Author

knuesel commented Jun 22, 2023

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?

@ericphanson
Copy link

Oh oops, no I just copied the example code as-is. I must've misread, sorry.

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

4 participants