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)[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?

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

1 Like

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.

2 Likes

Thanks, important point overlooked. Edited previous post with manual left padding. Not pretty but resulting figure looks OK.
Plots_gr_sublabel_lpad

2 Likes