# \`twiny\` in Plots somehow break the subplot margin

**URL:** <https://discourse.julialang.org/t/twiny-in-plots-somehow-break-the-subplot-margin/92901>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [January 12, 2023, 11:53pm UTC](https://discourse.julialang.org/t/twiny-in-plots-somehow-break-the-subplot-margin/92901 "2023-01-12T23:53:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![babaq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/babaq/32/891_2.png) [@babaq](https://discourse.julialang.org/u/babaq)\
**Post date:** [January 12, 2023, 11:53pm UTC](https://discourse.julialang.org/t/twiny-in-plots-somehow-break-the-subplot-margin/92901/1 "2023-01-12T23:53:15Z")

</div>

Hi,

For a subplot to have tight margins, i did this and plot looks fine.

```julia
p=plot(layout=(1,3),leg=false)
for i in 1:3
    leftmargin = i==1 ? 6Plots.mm : -4Plots.mm
    heatmap!(p[i],rand(10,10),yticks=[];leftmargin)
end
p

```

![image](https://global.discourse-cdn.com/julialang/original/3X/1/9/195dd93683f0c78e8d2a018675665cdaebbdde94.png)

but when i add a twiny for each subplots, it breaks the margins.

```julia
p=plot(layout=(1,3),leg=false)
for i in 1:3
    leftmargin = i==1 ? 6Plots.mm : -4Plots.mm
    heatmap!(p[i],rand(10,10),yticks=[];leftmargin)
    plot!(twiny(p[i]),rand(10),1:10;lw=2,leg=false,leftmargin)
end
p

```

![image](https://global.discourse-cdn.com/julialang/original/3X/c/7/c734965060eba3ccd3893963cbbd6127982db401.png)

Interestingly, set margin to same value for all subplots, would not break margins:

```julia
p=plot(layout=(1,3),leg=false)
for i in 1:3
    leftmargin = -4Plots.mm
    heatmap!(p[i],rand(10,10),yticks=[];leftmargin)
    plot!(twiny(p[i]),rand(10),1:10;lw=2,leg=false,leftmargin)
end
p

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/5/45440ae816698458a2ea1f4446fe8dc5230759d3.png)

is there a way to set different margins for each subplots with `twiny`?

Thanks,  
Alex
