# Plot a graph with specific sub labels

**URL:** <https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [September 20, 2021, 6:10pm UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491 "2021-09-20T18:10:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![maoc](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@maoc](https://discourse.julialang.org/u/maoc)\
**Post date:** [September 20, 2021, 6:10pm UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/1 "2021-09-20T18:10:07Z")

</div>

I need plot something with a particular axis labels. More specifically, sub-labels.

First, I’m gointo to plot the standar plot:

```julia
tg = 0:0.001:0.7
points = rand(size(tg)[1])

sublabels = fill("Julia", size(tg)[1] )
tab = [tg points]
sublabels[tab[:,1] .<= 0.2 ] .= "A"
sublabels[0.2 .< tab[:,1] .<= 0.6 ] .= "B"
sublabels[0.6 .< tab[:,1] .<= 0.7 ] .= "C"
tab = [tab sublabels]

plot(tab[:,1], tab[:,2], xlabel = "tax")

```

I would like to keep this graph and add these sub labels according to the last column of the matrix tab. The limits of these ranges must be highlighted. I would also like to keep the main “tax” label.

Some help?

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [September 21, 2021, 12:44am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/2 "2021-09-21T00:44:49Z")

</div>

It looks like you just want to add some sticks but I’m unsure. Could you quickly draft a picture of what you are looking for? Do you want something like this?

 ![Screen Shot 2021-09-21 at 10.42.15 am](https://global.discourse-cdn.com/julialang/original/3X/2/8/28fdbb7e2c601df56e367fb01c832035774d1562.png)

---

<div class="post-metadata">

**Author:** ![maoc](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@maoc](https://discourse.julialang.org/u/maoc)\
**Post date:** [September 21, 2021, 1:08am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/3 "2021-09-21T01:08:26Z")

</div>

Yes, but I would just like the labels 0.0 , 0.2 , 0.6 and 0.7 to appear. Overlaping B with 0.4 is not cool.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [September 21, 2021, 1:28am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/4 "2021-09-21T01:28:01Z")

</div>

Like [this](https://www.generic-mapping-tools.org/GMT.jl/dev/frames/#Custom-axes)?

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [September 21, 2021, 2:50am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/5 "2021-09-21T02:50:28Z")

</div>

> [@maoc](#):
>
> 0.0 , 0.2 , 0.6 and 0.7

Hacky way:

```julia
xlims = (-0.05, 0.75)
plot(tab[:,1], tab[:,2]; xlabel="tax", xticks=[0.0, 0.2, 0.6, 0.7], xlims)
plot!([NaN], [NaN]; label="", yticks=[],
    xticks=([0.1, 0.4, 0.65], ["A", "B", "C"]), tick_direction=:none,
    grid=:none,
    inset = (1, bbox(0.0, 0.0, 1.0, 1.0, :bottom, :right)),
    subplot = 2,
    bg_inside = nothing, xlims
)

```

gives

 ![Screen Shot 2021-09-21 at 12.50.19 pm](https://global.discourse-cdn.com/julialang/original/3X/6/8/685be29e248f5559ab881d36b46314b25662c7f7.jpeg)

---

<div class="post-metadata">

**Author:** ![maoc](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@maoc](https://discourse.julialang.org/u/maoc)\
**Post date:** [September 21, 2021, 2:59am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/6 "2021-09-21T02:59:45Z")

</div>

Thanks. If you wish, you can answer the same question I asked in this other forum.:  
[In Julia, Plot a graph with specific sub labels - Stack Overflow](https://stackoverflow.com/questions/69261051/in-julia-plot-a-graph-with-specific-sub-labels)

---

<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 21, 2021, 6:12am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/7 "2021-09-21T06:12:34Z")

</div>

Similar result could be obtained doing:

```julia
xt = [0, 0.2, 0.6, 0.7]
xt2 = [0, 0.2, 0.6]; xl2 = [lpad("A",40), lpad("B",80), lpad("C",20)]
plot(tab[:,1], tab[:,2], xlabel="tax", xticks=([xt; xt2], [string.(xt); xl2]))

```

_NB: added left padding_

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [September 21, 2021, 7:54am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/8 "2021-09-21T07:54:52Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> xt = [0, 0.2, 0.6, 0.7]
> xt2 = [0.1, 0.4, 0.65]; xl2 = ["A", "B", "C"]
> plot(tab[:,1], tab[:,2], xlabel="tax", xticks=([xt; xt2], [string.(xt); xl2]))
> 
> ```

But then you have the ticks and gridlines for the letter labels that I think are misleading you into thinking that A is exactly 0.1 instead of spanning from 0 to 0.2.

---

<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 21, 2021, 8:02am UTC](https://discourse.julialang.org/t/plot-a-graph-with-specific-sub-labels/68491/9 "2021-09-21T08:02:09Z")

</div>

Thanks, important point overlooked. Edited previous post with manual left padding. Not pretty but resulting figure looks OK.  
 ![Plots_gr_sublabel_lpad](https://global.discourse-cdn.com/julialang/original/3X/3/5/35e9090980260b7323f7542a274dfce9bc513a28.png)
