# Plot xticks correctly

**URL:** <https://discourse.julialang.org/t/plot-xticks-correctly/69652>\
**Category:** New to Julia\
**Tags:** plotting, plots\
**Created:** [October 13, 2021, 12:05am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652 "2021-10-13T00:05:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 13, 2021, 12:05am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/1 "2021-10-13T00:05:26Z")

</div>

I’m trying to reproduce this bar plot:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/b/0b634cdf963bd8f96de47e57e92a564b6b2dfde9.png)

With the following code:

```julia
using Plots,DelimitedFiles
f = readdlm("ch3_data_english.txt")
bar(f/100,
xticks = (1:26,'a':'z'),
yticks = 0:0.02:0.2,
ylims = (0,0.13),xlims = (1,26),
color = RGB(0.9,0.6,0),
label = false)

```

Which output is

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

My only complaint is that the little lines above the letters don’t show up, how do I fix that?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 13, 2021, 12:13am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/2 "2021-10-13T00:13:57Z")

</div>

[https://github.com/JuliaPlots/Plots.jl/issues/2218](https://github.com/JuliaPlots/Plots.jl/issues/2218)

---

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 13, 2021, 12:23am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/3 "2021-10-13T00:23:19Z")

</div>

That would be an interesting feature. I discovered that the ticks show up reducing the alpha argument, there is a way to plot the bars behind the ticks ?

---

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 13, 2021, 1:42am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/4 "2021-10-13T01:42:01Z")

</div>

Changing the backend to PyPlot and `a:z` to `string.(a:z)` the result is:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/9/a98577dfe183d179cca189aa22daa02073a6a420.png)

That’s almost perfect, now I only need the ticks to appear.

---

<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:** [October 13, 2021, 1:50am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/5 "2021-10-13T01:50:42Z")

</div>

The Box you can get with GR with `framestyle=:box`.

In case you don’t want to change the default backend (I noticed that this is one example of that book).

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [October 13, 2021, 5:10am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/6 "2021-10-13T05:10:17Z")

</div>

What’s the use of those ticks? There is one bar per label, and they are in direct connection. The fact that Plots.jl removes them is good-actually.

---

<div class="post-metadata">

**Author:** ![xinchin](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xinchin](https://discourse.julialang.org/u/xinchin)\
**Post date:** [October 13, 2021, 5:24am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/7 "2021-10-13T05:24:49Z")

</div>

I don’t think they r dropped, just they r being at the background. at `q` there is a small tick

---

<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 13, 2021, 7:11am UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/8 "2021-10-13T07:11:22Z")

</div>

Use the plots argument: `tick_direction=:out`, to get the ticks outside the box.

---

<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:** [October 13, 2021, 12:30pm UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/9 "2021-10-13T12:30:53Z")

</div>

It is probably not needed to reproduce exactly the same plot layout in reproducing those examples of the book. I guess the python and matlab codes that are shown do not produce identical plots either (keeping the code simple is likely a preferable goal).

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [October 13, 2021, 12:51pm UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/10 "2021-10-13T12:51:02Z")

</div>

Speaking of `xticks`, I am wondering if the docs of `Plots.jl` concerning the attributes are not wrong. [Here](https://docs.juliaplots.org/latest/generated/supported/), I can see `xsticks` instead of `xticks`. Is it a 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:** [October 13, 2021, 1:06pm UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/11 "2021-10-13T13:06:02Z")

</div>

> [@rveltz](#):
>
> `xsticks`

That seems to be a line type (_“sticks along x”_) for `gaston()` and `pgfplotsx()` backends. Not the same thing as `xticks` attribute:

```julia
using Plots; pgfplotsx()
plot(rand(10), lt=:xsticks)

```

 ![Plots_pgfplotsx_xsticks](https://global.discourse-cdn.com/julialang/original/3X/4/3/435cbb945c3ffae5ce91243c94c8b6c2a00e4914.png)

---

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 13, 2021, 1:09pm UTC](https://discourse.julialang.org/t/plot-xticks-correctly/69652/12 "2021-10-13T13:09:18Z")

</div>

That’s true, the pyhon code certainly do not reproduce a identical plot, I will choose a more simple approach.
