# CairoMakie Horizontal Colorbar

**URL:** <https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919>\
**Category:** Visualization\
**Tags:** cairomakie\
**Created:** [March 13, 2025, 2:06pm UTC](https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919 "2025-03-13T14:06:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew-saydjari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew-saydjari/32/19896_2.png) [@andrew-saydjari](https://discourse.julialang.org/u/andrew-saydjari)\
**Post date:** [March 13, 2025, 2:06pm UTC](https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919/1 "2025-03-13T14:06:18Z")

</div>

I cannot seem to find good documentation for how to make a horizontal color bar in CairoMakie. I found the vertical=false option, but I cannot seem to create a gap between the color bar and the plot (see example below) and it is not playing well with the plot title. Anyone have a MWE of a horiztonal color bar, with a gap, and a plot title?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/6/96ca8283acb1e61de0a745246bc601dc6834bc9a.jpeg)

---

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [March 13, 2025, 2:40pm UTC](https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919/2 "2025-03-13T14:40:48Z")

</div>

Here is a brute force and ignorance method from me:

```julia
        fig = Mke.Figure()
        ax1 = Mke.Axis(fig[2:5, 2], title="Spatial Distribution of Grant Funding", titlesize=10.0f0,
            subtitle=" ", subtitlesize=7.0f0,
            #=limits=(met.xaxismin, met.xaxismax, met.yaxismin, met.yaxismax),=#
            #xlabel="Easting", xlabelsize=7.0f0, xtickformat="{:.0f}", xticklabelsize=6.0f0,
            #ylabel="Northing", ylabelsize=7.0f0, ytickformat="{:.0f}", yticklabelsize=6.0f0,
            xlabelvisible=false, ylabelvisible=false, xticklabelsvisible=false, yticklabelsvisible=false,
            xticksvisible=false, yticksvisible=false, ygridvisible=false, xgridvisible=false,
            aspect=Mke.DataAspect())
        viz!(ax1, longt.geometry, color=longt.col, colormap=:lajolla, segmentcolor="black",
            showsegments=true, segmentsize=0.3f0, colorrange=log10.(cr))
        Mke.Colorbar(fig[6, 2], limits=cr, colormap="lajolla", scale=log10, tickformat=t_ft,
            ticklabelsize=7.0f0, label=ax_lab, labelsize=8.0f0, valign=:top, vertical=false, flipaxis=false)
        ax2 = Mke.Axis(fig[2:5, 1], title="Top Local Authority Recipients", titlesize=10.0f0,
            subtitle=pstitle, subtitlesize=7.0f0,
            yticks=(1:nticks, plotdf.newLocalAuthority), xtickformat=t_ft,
            limits=(cr, (0.5, nticks + 0.5)), xscale=log10, xticklabelsize=10.0f0, ygridvisible=false, xgridvisible=false,
            yticklabelsize=8.0f0, xlabel=ax_lab, xlabelsize=8.0f0,
            yticksvisible=false, yminorticks=0.5:1:nticks+0.5, yminorticksvisible=true, yminorticksize=3)
        Mke.barplot!(ax2, plotdf.nla, plotdf.rat, direction=:x, color=plotdf.rat, fillto=minimum(cr),
            colormap=:lajolla, colorrange=cr, colorscale=log10, strokecolor=:black, strokewidth=1)
        Mke.vlines!(ax2, 1, ymax=1, color=:red, linestyle=:dash)
        Mke.Label(fig[0, :], "Comparative Share of National Lottery Grant Funding\nAdjusted for Population Size", font=:bold, fontsize=16.0f0)
        Mke.Label(fig[1, :], stitle, fontsize=12.0f0)
        Mke.Legend(fig[6, 1], [Mke.LineElement(color=:red, linestyle=:dash)], ["England Average"], labelsize=7.0f0, tellheight=false,
            tellwidth=false, halign=:center, valign=:top, orientation=:horizontal, margin=(5, 5, 5, 5), height=30.0f0)
        Mke.save("tmp.pdf", fig)

```

I place each element into a notional 6x2 grid of elements on the page. There are two plots that fill position (2:5, 1) and (2:5, 2) on this grid. The colorbar goes under the right of these in position (6, 2) on the grid.

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

I’m sure there is a more elegant way!

---

<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:** [March 13, 2025, 3:22pm UTC](https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919/3 "2025-03-13T15:22:46Z")

</div>

Like this?

```julia
f = Figure()
Colorbar(f[1, 1], vertical = false, label = "Photometric g-band Epochs")
ax = Axis(f[2, 1])
rowgap!(f.layout, 1, 5)
f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/9/b95d427c8b5b6279e8bb596c388c65474f1bd111.png)

---

<div class="post-metadata">

**Author:** ![andrew-saydjari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew-saydjari/32/19896_2.png) [@andrew-saydjari](https://discourse.julialang.org/u/andrew-saydjari)\
**Post date:** [March 13, 2025, 3:43pm UTC](https://discourse.julialang.org/t/cairomakie-horizontal-colorbar/126919/4 "2025-03-13T15:43:34Z")

</div>

Yes. I think I had some psychological block in making the plot f[2,1] rather than f[1,1]. Thank you!
