# How to fix the rotated label position in this plot?

**URL:** https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025
**Category:** Visualization
**Tags:** plotting, plots, gr, pgfplotsx
**Created:** [September 11, 2021, 2:51pm UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025 "2021-09-11T14:51:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [September 11, 2021, 2:51pm UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/1 "2021-09-11T14:51:06Z")

</div>

Hi, I cannot figure how to correct the position of the rotated xticks label in the following plot:

```julia
using Plots

a=["absmax_global", "absmax_global_ref", "absmax_local"]
b=[0.03953348557784052, 1.0667377825188347, 1.9650133306504352]

title="absmax speed"

plt=bar(a,b,xrotation=20,ylabel = "GComp/s",
        title=title,label="",size=(600,400),
        tickfont=font(12),guidefont=font(12))
display(plt)

```

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

Thank you for your 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: [September 11, 2021, 4:56pm UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/2 "2021-09-11T16:56:44Z")

</div>

Hi Laurent, using Plots.jl’ pgfplotsx() back-end and just escaping the underscores, your code plots better:

 ![Plots_pgfplotsx_xticks_rotated_underscores_Latex](https://global.discourse-cdn.com/julialang/original/3X/f/e/fec1f4f52b929bb26c7030d2f4cdb1aad9c2ed76.png)

```julia
using Plots; pgfplotsx()

a=["absmax\\_global", "absmax\\_global\\_ref", "absmax\\_local"]
b=[0.03953348557784052, 1.0667377825188347, 1.9650133306504352]

title="absmax speed"

plt=bar(a,b, ylabel = "GComp/s",
        title=title,label="",size=(600,400),
        tickfont=font(12),guidefont=font(12),
        xrotation = 20)

```

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [September 12, 2021, 5:51am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/3 "2021-09-12T05:51:13Z")

</div>

Thank you Rafael.  
Is there a solution with default back-end (GR) ?  
(I use the sort of plot during training session and I would prefer to stick to basic/default tools).

---

<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: [September 12, 2021, 6:10am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/4 "2021-09-12T06:10:03Z")

</div>

For the gr() backend please check a manual tick solution in this [thread](https://discourse.julialang.org/t/bar-chart-with-rotated-x-label-for-each-bar/28554/2).

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [September 12, 2021, 9:13am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/5 "2021-09-12T09:13:45Z")

</div>

I try to follow the link and it seems that the manual tick method leads to the same problem…

```julia
using Plots

a=["absmax_global", "absmax_global_ref", "absmax_local"]
b=[0.03953348557784052, 1.0667377825188347, 1.9650133306504352]

title="absmax speed"

# plt=bar(a,b,xrotation=20,ylabel = "GComp/s",
# title=title,label="",size=(600,400),
# tickfont=font(12),guidefont=font(12))
l=length(a)
plt=bar(1:l,b, legend=false, xticks=(1:l,a), xrotation=20)
display(plt)
savefig(plt,"toto.png")

```

What is my mistake ?

---

<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: [September 12, 2021, 9:45am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/6 "2021-09-12T09:45:15Z")

</div>

It seems there [are bugs](https://github.com/JuliaPlots/Plots.jl/issues/2107#issuecomment-515040645) not fixed on this matter.  
Then we may need to get creative and use string padding:

```julia
using Plots; gr()

a=["absmax_global", "absmax_global_ref", "absmax_local"]
b=[0.03953348557784052, 1.0667377825188347, 1.9650133306504352]

title="absmax speed"
l=length(a)
plt=bar(1:l,b, legend=false, xticks=(1:l, a .* " "^18), xrotation=20)

```

 ![bar_xticks_labels_string_padded](https://global.discourse-cdn.com/julialang/original/3X/7/9/79e2d272af94fb196e5b2967b34a7a6243a6a3c5.png)

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [September 12, 2021, 9:51am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/7 "2021-09-12T09:51:09Z")

</div>

thank you very much ! Don’t know if this bug is a good news in general but I feel a bit release because I spent rather long time trying Plots options with no success 😆

---

<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: [September 12, 2021, 9:54am UTC](https://discourse.julialang.org/t/how-to-fix-the-rotated-label-position-in-this-plot/68025/8 "2021-09-12T09:54:12Z")

</div>

In example above, for padding the strings one could use the built-in function: `rpad.(a, 40)`, instead of `a .* " "^18`.
