I’m trying to get plots with transparent (nothing at all) background in Makie
using GLMakie
F = Figure()
ax = Axis(F[1,1])
θ = 0:0.1:2pi
X = cos.(θ)
Y = sin.(θ)
lines!(X,Y)
hidespines!(ax)
hidedecorations!(ax)
save("icon.png",F)
The saved file has a white background, is there anyway to make the background transparent (no background).
In Plots.jl one can do,
using Plots
θ = 0:0.1:2pi
X = cos.(θ)
Y = sin.(θ)
p=plot(X,Y, background_color=:transparent,
legend = false,ticks=false, axis=false)
savefig(p, "test.png")
really want to know how to do this in Makie
I am not certain this will work, but could you try:
ax = Axis(F[1,1], backgroundcolor=(:white,0))
Usually the element after the color is the alpha of the channel in other parts of Makie.
1 Like
Unfortunately it does not work😭.
jules
May 27, 2021, 8:46pm
5
The figure needs a transparent background, maybe Figure(backgroundcolor = :transparent)
and Axis(backgroundcolor = :transparent)
together?
sadly no.
I also tried to set both to (:white,0)
, and other combinations of the two, they all failed.
jules
May 27, 2021, 9:01pm
7
Maybe that’s a problem with the background in GLMakie @sdanisch ? I think it should be no problem in CairoMakie to get a fully transparent background
I tried CairoMakie, and didn’t work, maybe I’m doing something wrong😥
using CairoMakie
# if, for example, GLMakie is activated already
CairoMakie.activate!()
F = Figure(backgroundcolor = :transparent)
ax = Axis(F[1,1], backgroundcolor = :transparent)
θ = 0:0.1:2pi
X = cos.(θ)
Y = sin.(θ)
lines!(X,Y)
hidespines!(ax)
hidedecorations!(ax)
save("1221344.png",F)
jules
May 27, 2021, 9:28pm
9
for me it worked
using CairoMakie
f = Figure(backgroundcolor = :transparent)
Axis(f[1, 1], backgroundcolor = :transparent)
lines!(1:10)
save("test.png", f)
2 Likes
YES!!! This works!!! (After I restarted the kernel in Jupiter Lab)
jules
May 27, 2021, 9:33pm
11
nice, I’ll check why it doesn’t work in glmakie
1 Like
aramirezreyes:
(:white,0)
Setting backgroundcolor
in both Figure
and Axis
to (:white,0)
has the same effect as :transparent
in CairoMakie, they worked (failed in GLMakie )
F = Figure(backgroundcolor = (:white,0))
ax = Axis(F[1, 1], backgroundcolor =(:white,0))
jules
February 26, 2024, 3:18pm
13
For anyone finding this thread, there’s a workaround for GLMakie even if it cannot have transparent backgrounds natively
https://docs.makie.org/stable/how-to/save-figure-with-transparency/
2 Likes