Empty figure saved in Plots

I have an issue when trying to save pngs from subplots in a loop using the GR backend.

Plots.jl v1.22.1
GR v0.59.0

using Plots, Measures

x = 1:10
y = 1:10

l = @layout [a{0.01h}; grid(2,1)]

const ax = fill(plot(),3,1)

for i = 1:2
   ax[1] = plot(title="Big Title",
      framestyle=nothing,showaxis=false,xticks=false,yticks=false,margin=0mm)
   ax[2] = plot(x, y)
   ax[3] = plot(y, x)
   plot(ax..., layout=l)
   savefig("test_$i.png")
end

The first output is fine, but the second one is empty. Did I do something wrong here?

Did you try moving the layout definition into the for loop?

Without layout it works just fine. I find it relatively unintuitive to use the @layout macro…

It is is working fine here with the layout macro defined inside the loop:

using Plots, Measures
x = 1:10; y = 1:10
const ax = fill(plot(),3,1)
for i = 1:2
   l = @layout [a{0.01h}; grid(2,1)]
   ax[1] = plot(title="Big Title",
      framestyle=nothing,showaxis=false,xticks=false,yticks=false,margin=0mm)
   ax[2] = plot(x, y)
   ax[3] = plot(y, x)
   plot(ax..., layout=l)
   savefig("test_$i.png")
end

Oh sorry I misread your previous post. I’m so used to Matplotlib’s style. I don’t why it works this way though.