# PyPlot.jl reduce white space after tight\_layout()

**URL:** <https://discourse.julialang.org/t/pyplot-jl-reduce-white-space-after-tight-layout/86923>\
**Category:** Visualization\
**Tags:** plotting, pyplot\
**Created:** [September 8, 2022, 5:34am UTC](https://discourse.julialang.org/t/pyplot-jl-reduce-white-space-after-tight-layout/86923 "2022-09-08T05:34:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparrowhawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sparrowhawk/32/9148_2.png) [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Post date:** [September 8, 2022, 5:34am UTC](https://discourse.julialang.org/t/pyplot-jl-reduce-white-space-after-tight-layout/86923/1 "2022-09-08T05:34:33Z")

</div>

Can I reduce the amount of whitespace between subplots after the plot?

Please note I need AA and BB to have linked X, Y axes and the same sizes with a shared colorbar, and that AA, BB and CC need to have a shared X axis.

 ![drawing](https://global.discourse-cdn.com/julialang/original/3X/6/3/63fb36ae5ddde9fa9b57cd201e35f6a3ef565998.png)

Here’s the MWE

```julia
fig, ax = plt.subplots(4, 1, gridspec_kw=Dict("height_ratios" => [1,4,4,1]),
        figsize=(10,5))
ax[1].plot(rand(10))
ax[1].set_title("CC")
ax[2].imshow(rand(10,10), aspect="auto")        
ax[2].sharex(ax[1])
ax[2].set_title("BB")
imlast = ax[3].imshow(rand(10,10), aspect="auto")
ax[3].set_title("AA")
ax[3].set_xlabel("AA xlabel")
ax[3].sharex(ax[2])
map(x->x.tick_params(labelbottom=false), ax[1:end-2])
fig.colorbar(imlast, cax=ax[4], orientation="horizontal", label="Log₁₀ S/m")
fig.tight_layout()

```

The number of rows can vary, and `sharex` in the initial `subplots()` invocation above isn’t appropriate because of the `cax=ax[4]`

---

<div class="post-metadata">

**Author:** ![fedoroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedoroff/32/53209_2.png) [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Post date:** [September 8, 2022, 6:06am UTC](https://discourse.julialang.org/t/pyplot-jl-reduce-white-space-after-tight-layout/86923/2 "2022-09-08T06:06:30Z")

</div>

Take a look at [constrained\_layout](https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html#padding-and-spacing) guide with padding and spacing. I hope, it will help.

---

<div class="post-metadata">

**Author:** ![sparrowhawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sparrowhawk/32/9148_2.png) [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Post date:** [September 21, 2022, 6:22am UTC](https://discourse.julialang.org/t/pyplot-jl-reduce-white-space-after-tight-layout/86923/3 "2022-09-21T06:22:08Z")

</div>

Thanks, turns out that `tigh_layout()` even without constrained layout, can take an `h_pad` argument which can reduce the minimum space.
