# Plot a graph with specific sub labels

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

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

``````tg = 0:0.001:0.7
points = rand(size(tg))

sublabels =  fill("Julia", size(tg) )
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?

1 Like

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?

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.

Like this?

2 Likes

Hacky way:

``````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

2 Likes

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

1 Like

Similar result could be obtained doing:

``````xt = [0, 0.2, 0.6, 0.7]
plot(tab[:,1], tab[:,2], xlabel="tax", xticks=([xt; xt2], [string.(xt); xl2]))
`````` 