So I’m having an issue when I put a plot with a layout into another plot.
Consider the following example, my actual code is different (e.g., more pretty plotting and meaningful content), but this shows the problem already.
using Plots, Plots.Measures, GraphRecipes
# status Plots GraphRecipes
# [bd48cda9] GraphRecipes v0.5.5
# [91a5bcdd] Plots v1.14.0
make_plt(x) = scatter(rand(x), rand(x), legend = false, xticks = 0:.25:1, xlims = (0, 1))
function random_adjacency_mat(k)
adj = zeros(Int, k, k)
for i in 1:k-1, j in i+1:2
adj[i, i] = 1
if rand() <= .5
adj[i, j] = adj[j, i] = 1
end
end
adj[k, k] = 1
return adj
end
function get_xy(k)
offset = k == 4 ? pi / 4 : 0.0
x = Float64[sin(i * 2pi / k + offset) for i in 1:k]
y = Float64[cos(i * 2pi / k + offset) for i in 1:k]
return x, y
end
function make_axis_plt(k)
x, y = get_xy(k)
plt = plot(background_color_inside = plot_color(:red, 0.15), margin = 0.01mm)
graphplot!(plt, random_adjacency_mat(k), x = x, y = y, markersize = 0.2, nodeshape=:circle, fontsize = 10, linecolor = :darkgrey, nodecolor = plot_color(:white, 0.0), curves = false)
return plt
end
function make_plotmat()
x_axis_plots = [make_axis_plt(5) for _ in 1:5]
plotmat = Matrix{Plots.Plot}(undef, 2, 3)
for i in 1:3
l = @layout [
a{0.8h}
grid(1,length(x_axis_plots))
]
plt = make_plt(50)
plotmat[1, i] = deepcopy(plot(plt, x_axis_plots..., layout = l))
plotmat[2, i] = make_plt(50)
end
plotmat
end
plotmat = make_plotmat()
plotmat[1, 1] # figure 1
w = 300
plot(permutedims(plotmat)..., layout = (2, 3), size = (3w, 2w)) # figure 2
The first figure is what I intended to have:
There is one main plot and below it, there are 5 networks. The networks correspond to the x-axis ticks. Ideally, I’d show the networks instead of the ticks but this is the next best thing I came up with. Note that in the figure above, it is already slightly odd that the distance between the first and second network is not the same as the distance between the second and third, although I can live with that.
In the second figure, however, the networks look worse:
For some reason, the height of the first network is now different from that of the other networks within the same subplot!
Any ideas why the size changed, and how I can avoid this?