(Plots.jl) linked (aligned) x-axis figures with outer legends

I’m trying to align x-axis of subfigures where the subfigures have legends at e.g. :outerlefttop.

For example, inner legends imply aligned x-axis subfigures.

However, outer legends do not.

See also same Plots.jl Github issue here.

Umm… frankly speaking, I didn’t understand what you meant as the linked issue seems not about this question. Isn’t it?

EDIT: My question may be poor :slight_smile: What I want is to make all x axes’ length equal for subfigures when legends are placed out of figures.

It looks the same as one of the issues mentioned regarding outer legends and linked vertical subplots with axis not aligned:
Vertical_subplots_outerlegend

1 Like

Ah, it’s not a remedy but an already-reported issue. Got it.

Sorry, my bad. The issue reported does not seem to be the same.

1 Like

FWIW, for the github example linked above, the following workaround produces an equivalent plot, with “outer” legends and axis aligned:


using Printf, StatsPlots; gr()

d16mer = Dict("Making BioSeq"=> 0.719,
    "Iterating kmers"=> 0.104,
    "Checking sym kmer"=> 0.063,
    "Reading line"=> 0.06,
    "Creating kmer iterator"=> 0.037
    )

dcpg = Dict("Making BioSeq"=> 0.695,
    "Reading line"=> 0.06,
    "GpC detection"=> 0.046,
    "Length of seq"=> 0.032,
    "Indexing seq"=> 0.038
    )

function bp(dict; kw...)
    dict["Misc"] = 1 .- sum(values(dict))
    vals = reverse(collect(values(dict)))'
    labs = permutedims(reverse(collect(keys(dict))))
    groupedbar(vals, label = labs, bar_position = :stack, orientation=:horizontal,yticks = []; kw...)
end

x = LinRange(0,1,5)
xstr = [@sprintf("%.2f", xi) for xi in x]
a = bp(d16mer)
plot!(x, 0*x .+ ylims(a)[1], lc=:black,label=false,widen=false)
xticks!(x, xstr)
b = bp(dcpg)
plot!(x, 0*x .+ ylims(b)[1], lc=:black,label=false,widen=false)
xticks!(x, xstr)
plot(a,b, link=:x,layout=(2,1),xlims=(0,1.7),legend=:topright,showaxis=false)

Plots_gr_linked_vertical_sublplots_outerlegends

2 Likes

How did you do that?!

Is it related to the keyword argument widen=false?

It is just a inner that looks like an outer, by tricking the axes’ display. :slight_smile:

1 Like

Oh, got it. Nice!