In Plots.jl, can I have a single x axis for a grid of plots?

I have an array of plots (49 of them so it’s a fairly large figure)

plts = Plots.Plot[]
for i = 1:49 
   p = plot(...)
   push!(plts, p)
end
plot(plts..., layout = 49, size=(2000, 2000), link=:x, margin=-1mm)

I have two questions here

  1. Each plot gets its own x axis and y axis. Since the x-axis is the same for all plots, I’d like a single axis at the bottom of each column. I thought the link = :x would work, but I don’t know if I am using it correctly.

  2. The y-tick-labels have a large gap between the y axis. (note, I am not talking about the axis label… but the actualy axis-tick values). Is there a way to reduce this margin?

Maybe Plots.link_axes!()

Below outputs a set of 49 plots.

using Plots

C = [0.0005, 0.01, -0.003, 0.00029]
inS, outS = 52, 49
dampen = 0.95

X=zeros(Float64, inS)

# Create synthetic input set.
for i ∈ 1:inS
    X[i] = 0.125i
end

Y = zeros(Float64, (inS, outS))

# Create synthetic output set.
for k ∈ 1:length(Y[1,:])  # For each output Y[n].
    for j ∈ 1:length(X) # For each input X[n].
        Y[j, k]=(C[4]*(X[j]^3)+C[3]*(X[j]^2)+C[2]*X[j]+C[1]) * dampen
    end
    global dampen *= 0.95
end

plot(size=(1000, 1000))

for i ∈ 1:length(Y[1,:])
    display(plot!(X,Y[:,i]))
end


Actually, I meant something like this:

If you want to move beyond Plots.jl, you can look at https://github.com/JuliaPlots/AlgebraOfGraphics.jl. It builds a layer on top of AbstractPlotting/Makie. It can do this.

Queryverse is a nice option.

using Queryverse
using RDatasets: dataset

dataset("ggplot2", "mpg") |>
    @vlplot(:point, x=:Displ, y=:Hwy, column="Class:n", row="Cyl:n")

Maybe this is enough, inside an appropriate loop, using Plots:

julia> x = rand(10) ; y = rand(10) ;

julia> plot(layout=(2,2),framestyle=:box)

julia> plot!(x,y,xformatter=_->"",subplot=1)

julia> plot!(x,y,xformatter=_->"",yformatter=_->"",subplot=2)

julia> plot!(x,y,subplot=3)

julia> plot!(x,y,yformatter=_->"",subplot=4)

julia> plot!(xlim=[0,1],ylim=[0,1])

image

Another option - using MakieLayout, see an example with common y-axis from here: https://jkrumbiegel.github.io/MakieLayout.jl/stable/

it works for me with link=:all.