Grouped bar plots, with different number of bars in each group

Attempt with Makie :

using CairoMakie

function test_bar()
    d1 = [1,3,4,3,2]
    d2 = [2]
    d3 = [3]
    d4 = [5,3]

    fig = Figure(resolution = (1200, 800),fontsize = 32,colormap = (:Spectral_10, 0.85))  
    
    ax =  Axis(fig[1, 1])     
    ax.ylabel = "y label"
    ax.xlabel = "x label"

    ds=(d1,d2,d3,d4)
    
    shift=1
    gap=2
    xs,ys=Vector{Int}(),Vector{Int}()
    xticks=Vector{String}()
    for (i,di) ∈ enumerate(ds)
        b=shift
        shift+=length(di)
        newxs = collect(b:shift-1)
        xs = vcat(xs,newxs) 
        ys = vcat(ys,di)
        xticks = vcat(xticks,[string(i)*","*string(j) for j ∈ eachindex(di)])
        shift += gap
    end


    barplot!(xs,ys, strokewidth = 2,color=xs)
    ax.xticks = (xs, xticks)
    ax.xticklabelrotation = 45
    CairoMakie.save("toto.png",fig)

    fig
end

test_bar()
2 Likes