# Change xlabel position

**URL:** https://discourse.julialang.org/t/change-xlabel-position/78812
**Category:** Visualization
**Tags:** plots
**Created:** [March 31, 2022, 2:24pm UTC](https://discourse.julialang.org/t/change-xlabel-position/78812 "2022-03-31T14:24:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)
#### Post date: [March 31, 2022, 2:24pm UTC](https://discourse.julialang.org/t/change-xlabel-position/78812/1 "2022-03-31T14:24:04Z")

</div>

How can I adjust the position of the x-label in a plot using Plots.jl? e.g. if I do

```julia
using Plots
gr() # making it explicit I'm using the GR backend

plot(1:10, rand(1:2, 10))
xlabel!("my nice xlabel")

```

I get a plot with the xlabel centred:

![test](https://global.discourse-cdn.com/julialang/original/3X/f/4/f42ec313b2b87e0cffe68c718983e5de0d3b10f6.png)

**I want to change the x-position of the x-label**. If I try to add text centred around x = 7 using `annotate!`:

```julia
plot(1:10, rand(1:2, 10))
annotate!(7, 0.8, "my nice xlabel") # guessing y would be 0.8 for the text, based on the y-axis

```

I get a plot with no text, because `annotate!` only seems to add text to the figure area bounded by the axes:

![test](https://global.discourse-cdn.com/julialang/original/3X/d/8/d87db931448b3867522d545b70f54692471d2c75.png)

(whereas

```julia
annotate!(7, 1, "my nice xlabel")

```

adds text because y ∈ [1, 2], and y position for the text ∈ [1, 2]):

![test](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed59e31f93c9d631d2e5e0dccc71c934cd707304.png)

Are there any specific arguments I need to pass to `annotate!` in order for it to plot text in places outside the axes, or is there a more direct way of controlling the position of the x-label?

---

<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: [March 31, 2022, 4:42pm UTC](https://discourse.julialang.org/t/change-xlabel-position/78812/2 "2022-03-31T16:42:04Z")

</div>

> [@jewh](#):
>
> ```julia
> plot(1:10, rand(1:2, 10))
> annotate!(7, 0.8, "my nice xlabel")
> 
> ```

In the example the annotation is not showing up because it is outside of the figure margins. This works:

```julia
julia> using Plots, Plots.Measures

julia> plot(1:10, rand(1:2, 10),margin=1cm)

julia> annotate!(7, 0.8, "my nice xlabel")

```

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

---

<div class="post-metadata">

### Author: ![jewh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jewh/32/28586_2.png) [@jewh](https://discourse.julialang.org/u/jewh)
#### Post date: [March 31, 2022, 5:28pm UTC](https://discourse.julialang.org/t/change-xlabel-position/78812/3 "2022-03-31T17:28:45Z")

</div>

Lovely, thank you!
