# Adjusting padding between axis and axisticklabel in gridded layout

**URL:** <https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950>\
**Category:** Visualization\
**Tags:** plotting, plots, gr\
**Created:** [April 1, 2023, 2:39pm UTC](https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950 "2023-04-01T14:39:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iabraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iabraham/32/36532_2.png) [@iabraham](https://discourse.julialang.org/u/iabraham)\
**Post date:** [April 1, 2023, 2:39pm UTC](https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950/1 "2023-04-01T14:39:32Z")

</div>

This question is about being able to adjust the space between ticklabels and their corresponding axis lines in the default GR backed for Plots.jl.

Consider:

```julia
using Plots, Plots.Measures
minx, miny, N = 300, 300, 16

Plots.plot([Plots.plot(margin=0) for i in range(1,N*N)]..., layout=(N,N), 
           size=N.*(minx,miny), margin=0mm, ytickfonthalign=:left, dpi=200)

```

This generates a gridded layout as expected, **except** there is a humungous amount of space between the yticklabels and the y-axis. Funnily enough `ytickfonthalign=:left` actually reduces the space and `ytickfonthalign=:left` increases it. But more importantly, as you increase `N` the said spacing between the ticklabels and their axis actually keeps increasing.

Does anyone know how to reduce it? Setting negative margins didn’t help.

---

<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:** [April 1, 2023, 10:05pm UTC](https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950/2 "2023-04-01T22:05:38Z")

</div>

For such a large number of subplots, while that `gr()` backend bug is not fixed, it is best to use the `plotly()` backend.

Example:

```julia
using Measures, Plots; plotly()
N = 16
l = @layout grid(N, N)
plot(rand(10,N*N), layout=l, tickfontsize=5, margin=1mm, size=(200,200).*N)

```

---

<div class="post-metadata">

**Author:** ![iabraham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iabraham/32/36532_2.png) [@iabraham](https://discourse.julialang.org/u/iabraham)\
**Post date:** [April 2, 2023, 7:39pm UTC](https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950/3 "2023-04-02T19:39:47Z")

</div>

Thanks for this.

How do I save to PDF with the `plotly` backend?

It seems I can only save to HTML file format? Everything else keeps giving me this unhelpful error message:

```julia
julia> t=LinRange(0, 4π, 200);
julia> pp = plot(t, sin.(t))
julia> savefig(pp, "testfile.pdf")
ERROR: MethodError: no method matching _show(::IOStream, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.PlotlyBackend})
Closest candidates are:
  _show(::IO, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.GRBackend}) at ~/.julia/packages/Plots/9Q9pN/src/backends/gr.jl:2028
  _show(::IO, ::MIME{Symbol("application/vnd.plotly.v1+json")}, ::Plots.Plot{Plots.PlotlyBackend}) at ~/.julia/packages/Plots/9Q9pN/src/backends/plotly.jl:1102
  _show(::IO, ::MIME{Symbol("text/html")}, ::Plots.Plot{Plots.PlotlyBackend}) at ~/.julia/packages/Plots/9Q9pN/src/backends/plotly.jl:1105
  ...

```

I have fiddled around with the `plotlyjs` backend and it only got more complicated.

---

<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:** [April 2, 2023, 7:45pm UTC](https://discourse.julialang.org/t/adjusting-padding-between-axis-and-axisticklabel-in-gridded-layout/96950/4 "2023-04-02T19:45:00Z")

</div>

> [@iabraham](#):
>
> How do I save to PDF with the `plotly` backend?

If you will, open a new thread for a new topic.
