# Manual colorbar location with Makie

**URL:** https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533
**Category:** General Usage
**Tags:** makie
**Created:** [May 9, 2023, 7:22am UTC](https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533 "2023-05-09T07:22:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gravlax](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gravlax](https://discourse.julialang.org/u/Gravlax)
#### Post date: [May 9, 2023, 7:22am UTC](https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533/1 "2023-05-09T07:22:21Z")

</div>

Dear all,

I was wondering which is the best way to set the location of a colorbar (associated to a heatmap) with makie.  
I have tried the `bbox` argument without success. There is also the `translate!` function but it does not seem to apply to a colorbar.  
I am basically trying to make a colorbar as inset (like what’s done with line plots [there](https://juliadatascience.io/makie_layouts) ).  
I append (always the same :D) MWE below. I’d like to place the colorbar in the purple space located for x\>1.5.

Cheers!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/1/a102f9bf760035941e95489b7797938af9c38098.png)

```julia
# Mesh
    x = LinRange(-1.0, 3, 200)
    y = LinRange(-2.0, 2.0, 100)
    Lx, Ly = x[end]-x[1], y[end]-y[1]
    # One continuous field 
    f = 1e3.*exp.(-x.^2 .- (y').^2)
    # One discontinuous field 
    g = zero(f)
    g[(x.^2 .+ (y.^2)') .< 0.5^2] .= 1.0
    # Compose figure
    fig = Figure(resolution = (600, 600), fontsize = 22, fonts = (;regular="CMU Serif"))
    ax = fig[1, 1] = Axis(fig, xlabel = L"x", ylabel = L"y", aspect=Lx/Ly)
    hm = GLMakie.heatmap!(ax, x, y, f, colormap = (:plasma))
    GLMakie.contour!(ax, x, y, g)
    GLMakie.Colorbar(fig[1, 2], hm, label = L"\log_{10}[(u^2+v^2)^{1/2}]", width = 20,
        labelsize = 14, ticklabelsize = 14, bbox=BBox(500, 550, 100, 500))
    DataInspector(fig)
    display(fig)

```

---

<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: [May 9, 2023, 9:06am UTC](https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533/2 "2023-05-09T09:06:51Z")

</div>

If you specify a `bbox` you shouldn’t do `Colorbar(fig[1, 2])` because that also sets the bbox using the layout mechanism. It’s either or.

```julia
x = LinRange(-1.0, 3, 200)
y = LinRange(-2.0, 2.0, 100)
Lx, Ly = x[end]-x[1], y[end]-y[1]
# One continuous field 
f = 1e3.*exp.(-x.^2 .- (y').^2)
# One discontinuous field 
g = zero(f)
g[(x.^2 .+ (y.^2)') .< 0.5^2] .= 1.0
# Compose figure
fig = Figure(resolution = (600, 600), fontsize = 22, fonts = (;regular="CMU Serif"))
ax = fig[1, 1] = Axis(fig, xlabel = L"x", ylabel = L"y", aspect=Lx/Ly)
hm = heatmap!(ax, x, y, f, colormap = (:plasma))
contour!(ax, x, y, g)

Colorbar(fig, hm, label = L"\log_{10}[(u^2+v^2)^{1/2}]", width = 20,
    labelsize = 14, ticklabelsize = 14, bbox=ax.scene.px_area,
    alignmode = Outside(10), halign = :right, ticklabelcolor = :white, labelcolor = :white,
    tickcolor = :white)

fig

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e9d07cb6dc64818e09af14a56eefb721992fac4.png)
