Plots.jl xticks color modification

using Plots:
Plots_gr_with_multicolored_xticks

CODE
using Colors, Plots; gr(dpi=600)
theme(:dark)
colors0 = [:red, :orange, :yellow, :limegreen, :cyan, :blue, :violet, :brown, :black]

function multicolor_xticks!(colors0)
    p = Plots.current()
    xticks, xlabels = Plots.xticks(p)[1]
    yl = Plots.ylims(p)
    y0 = @. zero(xticks) + yl[1] - 0.06*(yl[2] - yl[1])
    n = length(xticks)
    colors = colors0[1:n]
    xticks!(xticks, fill(" ",n))
    [annotate!(xi,yi,text(li,9,ci,:bottom)) for (xi,yi,li,ci) in zip(xticks, y0, xlabels, colors)]
    return Plots.current()
end

# useage
plot(1:20, randn(20), xlabel="x", ylabel="y")
multicolor_xticks!(colors0)
1 Like