How to fix the rotated label position in this plot?

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

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

Thank you for your help !

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

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)
1 Like

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).

For the gr() backend please check a manual tick solution in this thread.

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

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 ?

It seems there are bugs not fixed on this matter.
Then we may need to get creative and use string padding:

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)

1 Like

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 :laughing:

2 Likes

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