# Makie - more idiomatic way to link x-axes of columns and y-axes of rows

**URL:** https://discourse.julialang.org/t/makie-more-idiomatic-way-to-link-x-axes-of-columns-and-y-axes-of-rows/88224
**Category:** Visualization
**Tags:** makie
**Created:** [October 4, 2022, 11:26am UTC](https://discourse.julialang.org/t/makie-more-idiomatic-way-to-link-x-axes-of-columns-and-y-axes-of-rows/88224 "2022-10-04T11:26:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![cripcate](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cripcate/32/34170_2.png) [@cripcate](https://discourse.julialang.org/u/cripcate)
#### Post date: [October 4, 2022, 11:26am UTC](https://discourse.julialang.org/t/makie-more-idiomatic-way-to-link-x-axes-of-columns-and-y-axes-of-rows/88224/1 "2022-10-04T11:26:37Z")

</div>

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:

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

```

 ![discourse_plot](https://global.discourse-cdn.com/julialang/original/3X/9/8/98e136fe15726b493a25d9c19fa0d2c58f3afade.png)

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
