# Changing distance between axes and x/y guides?

**URL:** <https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [October 19, 2021, 3:32pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043 "2021-10-19T15:32:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [October 19, 2021, 3:32pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/1 "2021-10-19T15:32:06Z")

</div>

How do I change the space between the frame/ticks/ticks numbers and the x/y axis guides? E.g. in this case:

```julia
plot(x -> x^2,xguide="X-axis",yguide="Y-axis")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/e/aec251209fd618886a4821f192798ba19b429874.png)  
(red markings are added to me to show what distance I want to change)

Especially when one does subplots, the distance can become quite significant:

```julia
plot(plot(x -> x^2,xguide="X-axis",yguide="Y-axis"),plot(x -> x^3,xguide="X-axis",yguide="Y-axis"),size=(700,350))

```

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

---

<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:** [October 19, 2021, 4:14pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/2 "2021-10-19T16:14:52Z")

</div>

For the 2nd case, a workaround: `using Measures` and add plot keyword argument to second subplot: `left_margin=10mm`

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [October 19, 2021, 4:47pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/3 "2021-10-19T16:47:14Z")

</div>

So, using

```julia
plot(plot(x -> x^2,xguide="X-axis",yguide="Y-axis"),plot(x -> x^3,xguide="X-axis",yguide="Y-axis",left_margin=10mm),size=(700,350))

```

partially solves it, in that the text is no longer closer to the left plot (than the right plot, to which it belongs):  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0074489d687d1b58bde7e7eb5fbbf2b40b36804.png)

However, the result is that you just get more space inbetweem and the space between the text and frame (of the right plot) does not change. The result is that you just get a very sparse plot, mostly filled with empty space, and less with the actual information.

---

<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:** [October 19, 2021, 7:20pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/4 "2021-10-19T19:20:30Z")

</div>

As you did not specify the backend, take `inspectdr()`, where you can adjust the plot layout interactively _(below is default look without editing)_:

```julia
using Plots; inspectdr()
plot(plot(x -> x^2, xguide="X-axis", yguide="Y-axis"),
     plot(x -> x^3, xguide="X-axis", yguide="Y-axis", size=(700,350)))

```

 ![Plots_inspectdr_subplots_ylabels](https://global.discourse-cdn.com/julialang/original/3X/3/7/3779a298f50afd69933d1e94d26950b3253e9ebf.png)

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [October 19, 2021, 8:10pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/5 "2021-10-19T20:10:27Z")

</div>

Think I am currently on gr (that’s the default?).

That looks really cool! Unfortunately, haven’t gotten those adjustment options, I run your code and get something like this:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/9/a98e38d00ab55b52b87cf5e5e1217eb21aca8185.png)

I have tried it both in Jupyter and VSCode.

---

<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:** [October 19, 2021, 10:58pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/6 "2021-10-19T22:58:22Z")

</div>

Please send the `inspectdr()` plot to an external window to get interactivity and some layout control. In VS Code settings [untick this box](https://discourse.julialang.org/t/plots-figure-size/37969/5).

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [October 20, 2021, 10:39am UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/7 "2021-10-20T10:39:05Z")

</div>

That worked, thanks.

---

<div class="post-metadata">

**Author:** ![parb](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@parb](https://discourse.julialang.org/u/parb)\
**Post date:** [June 20, 2023, 8:58am UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/8 "2023-06-20T08:58:32Z")

</div>

Great question, I’m having issues with this exact distance. It would be great if this distance could be modified with an axis attribute! My x- and y-axis labels / guides are much too far from their ticklabels, see below, and I don’t know how to fix this. I can replace all the labels by annotations, but this seems a poor hack.

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

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [December 2, 2024, 6:55pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/9 "2024-12-02T18:55:11Z")

</div>

This actually would be a great feature. Especially in plots with a lot of subplots the distance between guide and axis is too large.

---

<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:** [December 2, 2024, 7:29pm UTC](https://discourse.julialang.org/t/changing-distance-between-axes-and-x-y-guides/70043/10 "2024-12-02T19:29:23Z")

</div>

The simplest thing I would try first is:

1. to add a line break at the end of the `xlabel` strings and two line breaks at the beginning of the `ylabel` strings;
2. increase the margins by a few millimeters using `Measures`.
3. Adjusting plot size and dpi

> **MWE**
>
> ```julia
> using Measures, Plots; gr(dpi=1200)
> p = [plot(rand(10), rand(10), xlabel="xlabel\n", ylabel="\n\nylabel") for _ in 1:12]
> plot(p..., layout=(3, 4), size=(1600,1200), margins=2mm)
> 
> ```
