# Colorbar and colsize

**URL:** <https://discourse.julialang.org/t/colorbar-and-colsize/60093>\
**Category:** Visualization\
**Tags:** makie, makielayout\
**Created:** [April 27, 2021, 10:23am UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093 "2021-04-27T10:23:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [April 27, 2021, 10:23am UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/1 "2021-04-27T10:23:08Z")

</div>

I can’t figure out how to make this plot. I want a column of Aspect(1,1) heatmaps down the left, with matching rectangle plots on the right that take up the space.  
I can get here fine:

```julia
fig = Figure(resolution=(1192, 2024))

boxes = [Axis(fig[j,1]) for j in 1:4]

rects = [Axis(fig[j,2]) for j in 1:4]

colsize!(fig.layout,1,Aspect(1,1))

colsize!(fig.layout,2, Auto(1.5))

fig

```

 ![Screen Shot 2021-04-27 at 10.16.20 PM](https://global.discourse-cdn.com/julialang/original/3X/4/e/4ee427c9269d377cc3986ffc83d400a9714f27c1.png)

But now I want to add a colobar above the first square plot and make it scaled to the size. If I do `Colorbar(fig[0,1],vertical=false)` then the column width now refers to the colorbar width and the column shrinks to make the colorbar square:

 ![Screen Shot 2021-04-27 at 10.20.26 PM](https://global.discourse-cdn.com/julialang/original/3X/3/b/3bb3607939efe0a28b593fa344532f8ba582c0e9.png)

Trying `tellwidth=false` for the colorbar doesn’t help. Is there a way to keep the aspect ratio of the column plots, and add the colorbar that is above the first plot?

---

<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:** [April 27, 2021, 11:55am UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/2 "2021-04-27T11:55:53Z")

</div>

When you add the colorbar in row 0, row 1 becomes row 2 and your new row is row 1. That means your Aspect column size is now relative to the row that the colorbar is in (this doesn’t shift automatically right now, which might be considered a bug). So just refer the Aspect to the second row instead and it should be fine

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [April 27, 2021, 12:21pm UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/3 "2021-04-27T12:21:49Z")

</div>

Thanks… How do I do that? Can I pass this to Aspect() ? I couldn’t see it in docs

---

<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:** [April 27, 2021, 4:53pm UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/4 "2021-04-27T16:53:01Z")

</div>

Yeah the two parameters of aspect are the number of the row or column opposite of the column or row you apply aspect to, and then the aspect ratio against that. 1,1 doesn’t mean width 1 height 1, it means against row 1, ratio of 1(if applied to a column)

So it should be Aspect(2, 1) I think, from the top of my head

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [April 27, 2021, 8:49pm UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/5 "2021-04-27T20:49:06Z")

</div>

Great, thanks for this. Now my aspect is always square in the first column. I also wanted a legend above the second column. Since the right column is `Auto(1.5)` to take up the remaining space after the square plots, the legend should not report its size. Here is the result in case anyone finds it useful.

```julia
fig = Figure()

boxes = [Axis(fig[j,1]) for j in 1:2]
rects = [Axis(fig[j,2]) for j in 1:2]

colsize!(fig.layout,1,Aspect(2,1))
colsize!(fig.layout,2, Auto(1.5))

heatmap!(boxes[1],randn(30,30))
lines!(rects[1],-10..10,sin,label="sin")
lines!(rects[1],-10..10,cos,label="cos")

cbar = Colorbar(fig[0, 1],height=20,vertical=false,width=Relative(2/3))
Legend(fig[1,2],rects[1],tellwidth=false,orientation=:horizontal)
fig

```

 ![Screen Shot 2021-04-28 at 8.47.36 AM](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc2a0294bdddcb9992ca2d54b162bcc7c54f5a6e.png)

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [April 27, 2021, 8:53pm UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/6 "2021-04-27T20:53:49Z")

</div>

one last question: Can I label the colorbar  
to the left or right of it, or does it have to sit above?

---

<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:** [April 28, 2021, 5:55am UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/7 "2021-04-28T05:55:16Z")

</div>

The colorbar doesn’t have a setting to shift the label to the sides, but you can always put your own label there and don’t set the normal one at all. You can always put elements in the side protrusions of grid layout cells with the side specifiers such as Left() Right() etc. So for example you can do `Label(f[1, 1, Right()], "my label")`

It could be that you get a larger column gap this way than you want, but if the label is not too long you could just put it in its own small grid cell right next to the colorbar which could fill the rest of the column.

That would look a bit like

```julia
Colorbar(f[1, 1][1, 1])
Label(f[1, 1][1, 2])

```

---

<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:** [April 28, 2021, 10:00am UTC](https://discourse.julialang.org/t/colorbar-and-colsize/60093/8 "2021-04-28T10:00:51Z")

</div>

For example like this:

```julia
f = Figure(resolution = (1000, 1500))

[Axis(f[i+1, j]) for i in 1:5, j in 1:2]

colsize!(f.layout, 1, Aspect(2, 1))

Colorbar(f[1, 1][1, 1], vertical = false)
Label(f[1, 1][1, 2], "my label")

f

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/d/9/d91471c2a781d02fe04babcdc3fd1f07769929a0.png)
