Makie theme with transparent background not working

I would like to set once and for all the background of my axes and figures to be transparent. I thought I could do that as a theme in Makie.jl. The following minimal code fails to produce a transparent background

using CairoMakie
CairoMakie.activate!()

theme = Theme(
  Figure = (backgroundcolor = :transparent,),
  Axis = (backgroundcolor = :transparent,)
)
set_theme!(theme)

fig = Figure()
ax = Axis(fig[1, 1])
lines!(ax, 1:10, rand(10))

save("transparent_test.svg", fig)

whereas the intrusive instructions

fig = Figure(backgroundcolor = :transparent)
ax = Axis(fig[1, 1], backgroundcolor = :transparent)

work well.

Is there a way to setup the background transparency from a theme, or am I missing something?

You should try

theme = Theme(Axis = (backgroundcolor = :transparent))

see example in Themes | Makie.

1 Like

Block and plot objects can be themed by key, and Figure isn’t one of them, though I don’t know how specifying it could interfere. Figure doesn’t appear as a key in any of the predefined themes, either. Try following theme_dark and theme_black’s examples by replacing the Figure entry with a direct backgroundcolor = :transparent, hopefully it gels with the Axis’ own transparency.

1 Like

Thank you, the solution was in the end to modify the theme as follows:

theme = Theme(
  backgroundcolor = :transparent,
  Axis = (backgroundcolor = :transparent,)
)
1 Like

Thank you @raman_kumar for taking the time to answer. I’ve tried your solution but it was not working, because a field backgroundcolor = :transparent was needed in the main theme (outside axis, see below)

It’s for historical reasons, Scene was the only thing to theme at first so all its keys were top level. Figure is basically Scene so that stayed. Blocks and plot themes came later.

1 Like