# Makie - single bar label for stacked bar

**URL:** https://discourse.julialang.org/t/makie-single-bar-label-for-stacked-bar/122873
**Category:** Visualization
**Tags:** makie
**Created:** [November 20, 2024, 10:02pm UTC](https://discourse.julialang.org/t/makie-single-bar-label-for-stacked-bar/122873 "2024-11-20T22:02:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sleak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleak/32/15447_2.png) [@sleak](https://discourse.julialang.org/u/sleak)
#### Post date: [November 20, 2024, 10:02pm UTC](https://discourse.julialang.org/t/makie-single-bar-label-for-stacked-bar/122873/1 "2024-11-20T22:02:52Z")

</div>

I have a stacked bar plot, and can add a label to each block in the stack with `bar_labels=:y`. But this is noisy, and I’d like to only add a single label to the top of the stack, showing the total stacked value. How do I do that?

(here’s an example, borrowed from [Bar Label Alignment · Issue #3160 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/issues/3160))

```using

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,
        bar_labels = :y,
        axis = (xticks = (1:3, ["left", "middle", "right"]),),
    )

```

 ![Screenshot 2024-11-20 at 02.00.17 PM](https://global.discourse-cdn.com/julialang/original/3X/c/2/c2922c15f7a26b4dbbb45082bdca4c901cbb60fc.png)

I’d like it to show only the labels at the top of each bar, ie “0.6”, “1.5” and “2.4”

thanks!

---

<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: [November 20, 2024, 10:07pm UTC](https://discourse.julialang.org/t/makie-single-bar-label-for-stacked-bar/122873/2 "2024-11-20T22:07:01Z")

</div>

There’s no inbuilt convenience function to do that, but you can pass a vector of labels to `bar_labels` and you can make all that you want to hide `""`

---

<div class="post-metadata">

### Author: ![sleak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleak/32/15447_2.png) [@sleak](https://discourse.julialang.org/u/sleak)
#### Post date: [November 20, 2024, 10:34pm UTC](https://discourse.julialang.org/t/makie-single-bar-label-for-stacked-bar/122873/3 "2024-11-20T22:34:14Z")

</div>

Perfect!

```julia
using CairoMakie, Makie

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],
       )

barplot(
        tbl.x, tbl.height,
        stack = tbl.grp,
        color = tbl.grp,
        bar_labels = [g==3 ? "$h" : "" for (g,h) in zip(tbl.grp, tbl.height)],
        axis = (xticks = (1:3, ["left", "middle", "right"]),),
    )

```

 ![Screenshot 2024-11-20 at 02.33.52 PM](https://global.discourse-cdn.com/julialang/original/3X/b/a/babcb85475333e937c0127dc787cb323891e6e81.png)
