# Plots: subplot size changes when nesting plots with subplots & layout

**URL:** <https://discourse.julialang.org/t/plots-subplot-size-changes-when-nesting-plots-with-subplots-layout/61287>\
**Category:** Visualization\
**Tags:** question, plotting, plots, layout-plots\
**Created:** [May 17, 2021, 9:14am UTC](https://discourse.julialang.org/t/plots-subplot-size-changes-when-nesting-plots-with-subplots-layout/61287 "2021-05-17T09:14:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vandenman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vandenman/32/10837_2.png) [@vandenman](https://discourse.julialang.org/u/vandenman)\
**Post date:** [May 17, 2021, 9:14am UTC](https://discourse.julialang.org/t/plots-subplot-size-changes-when-nesting-plots-with-subplots-layout/61287/1 "2021-05-17T09:14:32Z")

</div>

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.

```julia
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:

![figjulia_1](https://global.discourse-cdn.com/julialang/original/3X/c/4/c4cdd527963137fd67b0e586aa5a9ae64ed1d35e.png)

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:

 ![figjulia_2](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b14162d58f1c9ed862b0cb226cbcd6ef3b14655.png)

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?
