Makie.jl Export with transparent background

I have a high resolution dataset, about 1000x1000 points for which I want to export the surface plot, like in

fig = Figure(resolution = (1000, 1300), figure_padding = (0, 26, 2, 0))
axis = Axis3(fig[1, 1],
  azimuth = π/6, elevation = π/8, aspect = (1, 1, 1.3),
  backgroundcolor = :transparent
)
surface!(axis, xs, ys, data)

When I export the figure, like with save("myfigure.png", fig) however, Makie completely ignores the :transparent option. I tested both CairoMakie and GLMakie, and manually set the background via RGBA instead of the :transparent flag.

I assume the problem does not exist with vector graphics, but to the fine grained data set the resulting pdf is easily a few GB and thus unusable in further processing steps. Reducing the resolution is sadly not possible, I tested that, leading to unwanted artefacts or misrepresents the data. The resulting figure will be used in a cover, so a highly detailed image is wanted and necessary

Thus the questions:

  1. Does Makie by default use a png encoding without transparency support? If so, how to tell Makie to change that?
  2. Any other way to get the wanted result? I considered rasterising the resulting pdf, but every tool I know crashed to the immense size of the resulting figure.

The Figure has a white background color by default, so set :transparent on that. Cairomakie can output transparent pngs, for GLMakie I once wrote a workaround (its buffer is only RGB for technical reasons) but I’d have to look it up first.

Also, with CairoMakie (and soon with GLMakie as well) you can use px_per_unit = 2 or higher when saving to increase the resolution.

3 Likes