# Empty figure saved in Plots

**URL:** <https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585>\
**Category:** General Usage\
**Tags:** plots, gr\
**Created:** [September 22, 2021, 2:43pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585 "2021-09-22T14:43:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [September 22, 2021, 2:43pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585/1 "2021-09-22T14:43:38Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 22, 2021, 3:39pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585/2 "2021-09-22T15:39:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [September 22, 2021, 3:44pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585/3 "2021-09-22T15:44:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 22, 2021, 3:47pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585/4 "2021-09-22T15:47:35Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [September 22, 2021, 3:50pm UTC](https://discourse.julialang.org/t/empty-figure-saved-in-plots/68585/5 "2021-09-22T15:50:20Z")

</div>

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