# Does BBox work with GridLayout?

**URL:** <https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [July 24, 2023, 1:57pm UTC](https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023 "2023-07-24T13:57:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [July 24, 2023, 1:57pm UTC](https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023/1 "2023-07-24T13:57:10Z")

</div>

I want to create a graph with multiple axis and move them across the plot. I worked perfectly with Figure(), but do not work with GridLayout(), which I need to make combined figure.

How can I solve this problem?

How it should be:

 ![plot5](https://global.discourse-cdn.com/julialang/original/3X/9/8/98bf9655d6a76567b4f8003005571c2b2d777909.jpeg)

How it is now:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/0/c0deb9f7a92dff19fbf1560aa816820e743dcebc.jpeg)

The code before:

```julia

begin
    times = range(-0.3, length=size(dat_e, 2), step=1 ./ 128)

    f = Figure()
    for i in 1:30
        xmove = pos[i][1] *1000 - 120
        ymove = pos[i][2] * 800 - 100
        ax = Axis(f, bbox = BBox(xmove, xmove+90, ymove, ymove+30), title = string(raw.ch_names[i]))
        mean_trial = mean(dat_e[i,:,:], dims=2)[:,1]
        lines!(ax, times, mean_trial, color = "#0077b6") #, model = m4x4)
        hlines!(0, color = :gray, linewidth = 1)
        vlines!(0, color = :gray, linewidth = 1)
        hidespines!(ax) 
        hidedecorations!(ax)
        Makie.ylims!(low = -8, high = 14)
    end
    f
end

```

The code now:

```julia
function topo_array(f) 
    times = range(-0.3, length=size(dat_e, 2), step=1 ./ 128)
    
    for i in 1:30
        xmove = pos[i][1] *1000 - 120
        ymove = pos[i][2] * 800 - 100
        ax = Axis(f[1, 1], bbox = BBox(xmove, xmove+90, ymove, ymove+30), title = string(raw_ch_names[i]))
        mean_trial = mean(dat_e[i,:,:], dims=2)[:,1]
        lines!(ax, times, mean_trial, color = "#0077b6") #, model = m4x4)
        hlines!(0, color = :gray, linewidth = 1)
        vlines!(0, color = :gray, linewidth = 1)
        hidespines!(ax) 
        hidedecorations!(ax)
        Makie.ylims!(low = -8, high = 14)
    end
    f
end
topo_array(GridLayout())

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [July 25, 2023, 9:16am UTC](https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023/2 "2023-07-25T09:16:53Z")

</div>

I can’t run the code since variables are missing…  
Can you update so I can try this out?

---

<div class="post-metadata">

**Author:** ![vladdez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vladdez/32/45806_2.png) [@vladdez](https://discourse.julialang.org/u/vladdez)\
**Post date:** [July 25, 2023, 10:54am UTC](https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023/3 "2023-07-25T10:54:58Z")

</div>

How about this code:

```julia
using UnfoldMakie
using Unfold
using CairoMakie
using DataFrames

begin 
	df, pos = example_data("TopoPlots.jl")
	df = filter(x -> (x.channel <= 32), df)
	ch_vector = [
		"FP1", "F3", "F7", "FC3", "C3", "C5", "P3", "P7", "P9", "PO7",
		"PO3", "O1", "Oz", "Pz", "CPz", "FP2", "Fz", "F4", "F8", "FC4",
		"FCz", "Cz", "C4", "C6", "P4", "P8", "P10", "PO8", "PO4", "O2"
	]
	f = Figure(backgroundcolor=RGBf(0.98, 0.98, 0.98),
    resolution=(1000, 700))
	ga = f[1, 1] = GridLayout()
	gb = f[2, 1] = GridLayout()
	gcd = f[1:2, 2] = GridLayout()
	gc = gcd[1, 1] = GridLayout()
	gd = gcd[2, 1] = GridLayout()
	gef = f[1:2, 3] = GridLayout()
	ge = gef[1, 1] = GridLayout()
	gf = gef[2, 1] = GridLayout()

	function topo_array(f) 
	
		for i in 1:30
			tmp = filter(x -> (x.channel == i), df)

			xmove = pos[i][1] *1000 - 120
			ymove = pos[i][2] * 800 - 100
			ax = Axis(f[1, 1], bbox = BBox(xmove, xmove+90, ymove, ymove+30), title = ch_vector[i])
			lines!(ax, df.time, df.estimate, color = "#0077b6") #, model = m4x4)
			hlines!(0, color = :gray, linewidth = 1)
			vlines!(0, color = :gray, linewidth = 1)
			hidespines!(ax) 
			hidedecorations!(ax)
			Makie.ylims!(low = -8, high = 14)
		end
		
		f
	end

	topo_array(gf)
	f
end

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 25, 2023, 11:03am UTC](https://discourse.julialang.org/t/does-bbox-work-with-gridlayout/102023/4 "2023-07-25T11:03:15Z")

</div>

When you use `bbox` you manually say which rectangle in the Figure or Scene you want to place a Block in. This does not work together with assigning the Block to a specific layout position, because then that layout position will decide where the object ends up. I can see two paths forward. Either you try `ls = LScene(gridposition; camera = campixel!)` and then you do `Axis(ls.scene, bbox = ...)` or you check what rectangle a given `GridLayout` occupies, by looking into `glayout.layoutobservables.computedbbox` and then computing your desired positions within that rectangle.
