# Cannot change colorbar position

**URL:** <https://discourse.julialang.org/t/cannot-change-colorbar-position/17181>\
**Category:** Visualization\
**Tags:** question, pyplot, plots, pgfplotsx\
**Created:** [November 5, 2018, 6:01pm UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181 "2018-11-05T18:01:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shipengcheng1230](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shipengcheng1230/32/4089_2.png) [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Post date:** [November 5, 2018, 6:01pm UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/1 "2018-11-05T18:01:50Z")

</div>

I am trying to change the colorbar position:

```julia
using Plots
# pyplot()
plot(rand(10, 2), marker_z=rand(10), seriestype=:scatter, cb=:top)

```

But the colorbar position won’t move no matter how I specifiy `:cb`:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/9/79febd92046836d195563ce8df655d31a73dc568.png)

It is always on the right side of the image.

I tried using Plots and PyPlot backends, in terminal and IJulia both, which all didn’t work. All the package are up-to-date. Any ideas how may I achieve this? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [May 19, 2020, 12:34am UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/2 "2020-05-19T00:34:43Z")

</div>

I am facing the same issue, any trick to go around this issue?

---

<div class="post-metadata">

**Author:** ![josephmarturano](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@josephmarturano](https://discourse.julialang.org/u/josephmarturano)\
**Post date:** [May 19, 2020, 3:32pm UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/3 "2020-05-19T15:32:01Z")

</div>

Positioning the colorbar can be tricky since some plotting packages do not support any position except to the right of the plot. But as one method, you can use PyPlot.jl directly and place the colorbar underneath the plot, e.g.,:

```julia
using PyPlot
fig, ax = plt.subplots(figsize=(4,4))
mesh = ax.pcolormesh(rand(10, 10))
fig.colorbar(mesh, orientation="horizontal")
gcf()

```

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [April 26, 2022, 4:41pm UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/4 "2022-04-26T16:41:55Z")

</div>

This does now work with pyplot backend:

![Figure_1](https://global.discourse-cdn.com/julialang/original/3X/2/9/29668c5758028977b2aceb60c919a40249cadab2.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 26, 2022, 5:00pm UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/5 "2022-04-26T17:00:11Z")

</div>

Fyi, the `plot(colorbar=:top)` argument also works with the `pgfplotsx()` backend.

 ![Plots_pgfplotsx_top_colorbar](https://global.discourse-cdn.com/julialang/original/3X/0/6/06053d9413bde5321e516f058b05f8e11d224ce5.png)

---

<div class="post-metadata">

**Author:** ![zhiyuanzhai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhiyuanzhai/32/9519_2.png) [@zhiyuanzhai](https://discourse.julialang.org/u/zhiyuanzhai)\
**Post date:** [May 1, 2022, 5:06am UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/6 "2022-05-01T05:06:57Z")

</div>

But the colorbar title is still weird for this. It will go to the left of the bar…

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 1, 2022, 9:13am UTC](https://discourse.julialang.org/t/cannot-change-colorbar-position/17181/7 "2022-05-01T09:13:13Z")

</div>

Plots.jl can be tamed using Measures and layouts:

 ![Plots_pgfplotsx_horizontal_colorbar_and_title](https://global.discourse-cdn.com/julialang/original/3X/7/9/79f67359c641a185a378f9b8a931fb76449f1d6e.png)

```julia
using Measures, Plots; pgfplotsx()
l = @layout [a{0.1h}; b]
p1 = plot(frame=:none, title="CB title", titlefontsize=10, bottom_margin=-25mm);
p2 = plot(rand(10,2), marker_z=rand(10), st=:scatter, cb=:top);
plot(p1, p2, layout=l)

```
