Hello everyone.
I am trying to create a grid of axes, plot some data into each of them, and then link all the y-axes of each row of plots and all x-axes of each column of plots. The reason for this is that I want to plot various dependent variables (rows of plots, y-axes) against various independent ones (columns, x-axes) of the same dataframe. So in one row of plots, all y-axes represent the same dependent variable, and in one column of plots, all x-axes represent the same independent variable. Therefore I want these axes to be linked.
I managed to achieve the desired behavior like this:
let f = Figure()
xn = 4
yn = 3
axs = Array{Makie.Axis}(undef, (yn, xn))
# Simplified, using dummy data
for i in 1:yn # Iterate over different columns of dataframe to plot on y-axes
for j in 1:xn # Iterate over different columns of dataframe to plot on y-axes
ax = Axis(f[i, j])
plot!(ax, rand(10) .* i ./ j, rand(10) .* i ./ j)
axs[i, j] = ax
end
end
for i in 1:yn # Link the y-axes of each row
linkyaxes!(axs[i, :]...)
end
for i in 1:xn # Link the x-axes of each column
linkxaxes!(axs[:, i]...)
end
f
end
I initialized an array of axis objects beforehand, iterate over my data, plot each variable pair on a new axis, and put that axis on the respective position in the array. Afterwards i need to iterate over each row and link the y-axes and over each column to link the x-axes.
While this method works, I am sure there is a much shorter, more intuitive and more idiomatic way to do this. This is why I am writing this post and asking for advice on how to simplify what I am doing. Maybe someone got ideas
Cheers,
Nils