# Makie stacked bar chart legends & labels inside axis

**URL:** https://discourse.julialang.org/t/makie-stacked-bar-chart-legends-labels-inside-axis/66706
**Category:** Visualization
**Tags:** makie
**Created:** [August 20, 2021, 4:36am UTC](https://discourse.julialang.org/t/makie-stacked-bar-chart-legends-labels-inside-axis/66706 "2021-08-20T04:36:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bicepjai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicepjai/32/18158_2.png) [@bicepjai](https://discourse.julialang.org/u/bicepjai)
#### Post date: [August 20, 2021, 4:36am UTC](https://discourse.julialang.org/t/makie-stacked-bar-chart-legends-labels-inside-axis/66706/1 "2021-08-20T04:36:43Z")

</div>

1. ~~How to place legend for stacked bar chart inside an axis. This can save lot of space on plots.~~
2. How to place labels when drawing stacked bar chart

Sample code can be found in makie examples [here](http://makie.juliaplots.org/stable/plotting_functions/barplot.html)

```julia
using CairoMakie

tbl = (x = [1, 1, 1, 2, 2, 2, 3, 3, 3],
       height = 0.1:0.1:0.9,
       grp = [1, 2, 3, 1, 2, 3, 1, 2, 3],
       grp1 = [1, 2, 2, 1, 1, 2, 1, 1, 2],
       grp2 = [1, 1, 2, 1, 2, 1, 1, 2, 1]
       )
barplot(tbl.x, tbl.height,
        stack = tbl.grp,
        color = tbl.grp,
        axis = (xticks = (1:3, ["left", "middle", "right"]),
                title = "Stacked bars"),
        )

```

---

<div class="post-metadata">

### Author: ![bicepjai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicepjai/32/18158_2.png) [@bicepjai](https://discourse.julialang.org/u/bicepjai)
#### Post date: [August 20, 2021, 6:58pm UTC](https://discourse.julialang.org/t/makie-stacked-bar-chart-legends-labels-inside-axis/66706/2 "2021-08-20T18:58:44Z")

</div>

Found the way to update legends inside

```julia
    CM.axislegend(ax1, 
        [PolyElement(polycolor = colors[i]) for i in [1,2]], 
        ["one","two"], "", 
        position = :lt, orientation = :horizontal)

```
