I was wondering if there is a way to specify a common x- or y-label easily in Plots.jl when plotting one figure with multiple subplots.
The following creates subplots with the same axes labels for both figures, but printed for each figure:
I would find this useful as well – for grid layouts that is. It would not be hard to write a function that does this, but it would a bit fragile (dependent on internals of Plots.jl). Something like:
using Plots
function ylabels_from_grid(l :: Plots.GridLayout, yStr)
n = length(l.grid)
nCols = size(l.grid, 2)
yV = fill("", n);
for j = 1 : n
if rem(j, nCols) == 1
yV[j] = yStr;
end
end
return yV
end
# Make a layout
l = @layout grid(2,2);
yV = ylabels_from_grid(l, "Y label");
# Plot some things
pV = Vector{Any}(undef, 4)
for j = 1 : 4
pV[j] = plot(1:10, 1:10, xlabel = "$j", ylabel = yV[j])
end
p = plot(pV..., layout = l)
link is especially useful if you use the interactive plots of Plotly (by calling plotly() before you make your plot) so that when you zoom into one subplot, the other plots stay synchronized.