# Layouts of a plot and of the same in a subplot

**URL:** <https://discourse.julialang.org/t/layouts-of-a-plot-and-of-the-same-in-a-subplot/76901>\
**Category:** General Usage\
**Tags:** plotting, plots, gr, layout-plots\
**Created:** [February 22, 2022, 10:44am UTC](https://discourse.julialang.org/t/layouts-of-a-plot-and-of-the-same-in-a-subplot/76901 "2022-02-22T10:44:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maajdl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maajdl/32/22838_2.png) [@maajdl](https://discourse.julialang.org/u/maajdl)\
**Post date:** [February 22, 2022, 10:44am UTC](https://discourse.julialang.org/t/layouts-of-a-plot-and-of-the-same-in-a-subplot/76901/1 "2022-02-22T10:44:10Z")

</div>

**Continuing the discussion** from [Plot size from subplots sizes](https://discourse.julialang.org/t/plot-size-from-subplots-sizes/76542/3) !  
The discussion was about the layout changes illustrated below.  
The first plot was good-looking, but the combination in subplots was not.  
**A useful workaround** was to add a 5mm margin in the second test to make it more readable.  
However, when combining other kinds of plots in a subplot, the problem pops up again and again.  
**The problem boils down to the fact** that even when providing the correct space for the subplots,  
the layout of the subplots are strongly modified, not only the sizes, margins and other elements are different, but even the aspect ratio of the frame is modified.  
**I included a 3rd test** showing that increasing the width of the initial plot leads to a similar distortion. This may give a clue to what is happening.

Would you know any reason for this behaviour?  
Would you know a way to avoid it in a reproducible way?

Thanks

Michel

* * *

**Test 1: a 400x300 plot**

```julia
p = testplot()
plot(p)

```

![p](https://global.discourse-cdn.com/julialang/original/3X/5/d/5dcb07eb61271cff4cb270d7ef4bdf70fdcfd876.jpeg)

**Test 2: a 800x300 plot with two subplots as above (400x300)**

```julia
p = testplot()
plot(p,p, layout=grid(1,2, widths=(400/800, 400/800)), size=(800,300))

```

![pp](https://global.discourse-cdn.com/julialang/original/3X/1/2/12ac974bb050ed6ac71e6122056c898a20394bf0.jpeg)

**Test 3: similar behaviour when plotting same plot twice larger** (compare to test 1)

```julia
plot(p, size=(800,300))

```

 ![download](https://global.discourse-cdn.com/julialang/original/3X/d/2/d22444138be75d984bb9fabc2cb3963c7386db63.jpeg)

**Source code of testplot()**

```julia
using Plots

function testplot()
    Di = 1:9
    Ei = [215, 125, 89, 69, 56, 47, 41, 36, 32]
    Oi = [216, 163, 88, 74, 61, 40, 25, 26, 22]
    markColor = [:green,:red,:green,:green,:green,:green,:red,:red,:red]
    title = "This is a test\n N=175, chi²=26 ** Poor fit"
    p = plot(xtickfontsize=8,ytickfontsize=8,xguidefontsize=8,yguidefontsize=8, titlefont=font(10))
    plot!(size=(400,300), background_color="ivory", framestyle = :box)
    plot!(title=title, xlabel="digit", ylabel="count")
    plot!(xticks=Di, ylim=(0,Inf))
    plot!(Di, Ei, ribbon=1*sqrt.(Ei), label="1σ CI", fillcolor="gray65")
    plot!(Di, Ei, ribbon=2*sqrt.(Ei), label="2σ CI", fillcolor="gray85")
    scatter!(Di, Oi, label="data", markercolor=markColor)
end

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 22, 2022, 12:04pm UTC](https://discourse.julialang.org/t/layouts-of-a-plot-and-of-the-same-in-a-subplot/76901/2 "2022-02-22T12:04:33Z")

</div>

Just a simplified example:

```julia
using Plots
plot(rand(10),size=(400,300),title="This is a test",xlabel="Test",ylabel="Test")

```

![image](https://global.discourse-cdn.com/julialang/original/3X/5/0/50f84dee331b64dcfd90ae574ca011ad70602b0b.png)

```julia
plot(rand(10),size=(800,300),title="This is a test",xlabel="Test",ylabel="Test")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/2/12550b878cb1412bb173aa0bd5e7077858a34317.png)

---

<div class="post-metadata">

**Author:** ![maajdl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maajdl/32/22838_2.png) [@maajdl](https://discourse.julialang.org/u/maajdl)\
**Post date:** [February 22, 2022, 3:10pm UTC](https://discourse.julialang.org/t/layouts-of-a-plot-and-of-the-same-in-a-subplot/76901/3 "2022-02-22T15:10:57Z")

</div>

Looks like a bug or an inconsistency in how the layout depends on the width.  
I cant see any sense there.  
Michel
