Stacked Bar Chart with Total Labels in Makie.jl (Julia)

The same plot in 14 other libraries — Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts, MUI X Charts. Compare all 15 side by side: Stacked Bar Chart with Total Labels in Python, R, Julia and JavaScript.

A stacked bar chart that displays multiple data series stacked on top of each other with total value labels prominently shown above each bar stack. This variant combines part-to-whole visualization with explicit numerical annotations, making it easy to read both individual segment contributions and cumulative totals at a glance. The total labels eliminate the need for mental arithmetic when comparing overall values across categories.

Stacked Bar Chart with Total Labels rendered with Makie.jl

Renders

Julia source (Makie.jl)

# anyplot.ai
# bar-stacked-labeled: Stacked Bar Chart with Total Labels
# Library: makie 0.21.9 | Julia 1.11.9
# Quality: 90/100 | Created: 2026-08-26

using CairoMakie
using Colors

# --- Theme tokens -----------------------------------------------------------
const THEME    = get(ENV, "ANYPLOT_THEME", "light")
const PAGE_BG  = THEME == "light" ? colorant"#FAF8F1" : colorant"#1A1A17"
const INK      = THEME == "light" ? colorant"#1A1A17" : colorant"#F0EFE8"
const INK_SOFT = THEME == "light" ? colorant"#4A4A44" : colorant"#B8B7B0"

const IMPRINT_PALETTE = [
    colorant"#009E73", colorant"#C475FD", colorant"#4467A3", colorant"#BD8233",
    colorant"#AE3030", colorant"#2ABCCD", colorant"#954477", colorant"#99B314",
]

# --- Data -------------------------------------------------------------------
# Quarterly SaaS revenue split by product line ($M, illustrative).
quarters      = ["Q1", "Q2", "Q3", "Q4"]
product_lines = ["Subscriptions", "Services", "Hardware", "Support"]

revenue = [
    5.2 2.1 0.9 0.5
    5.8 2.3 0.8 0.5
    6.5 2.6 0.9 0.6
    7.3 3.0 0.9 0.7
]

n_quarter = length(quarters)
n_product = length(product_lines)

x      = repeat(1:n_quarter, inner = n_product)
stack  = repeat(1:n_product, outer = n_quarter)
height = vec(permutedims(revenue))

totals = vec(sum(revenue, dims = 2))

# --- Plot ---------------------------------------------------------------
fig = Figure(
    size            = (1600, 900),
    fontsize        = 14,
    backgroundcolor = PAGE_BG,
)

ax = Axis(
    fig[1, 1];
    title             = "bar-stacked-labeled · julia · makie · anyplot.ai",
    titlesize         = 20,
    titlecolor        = INK,
    xlabel            = "Quarter",
    ylabel            = "Revenue (\$M)",
    xlabelsize        = 14,
    ylabelsize        = 14,
    xlabelcolor       = INK,
    ylabelcolor       = INK,
    xticklabelsize    = 13,
    yticklabelsize    = 12,
    xticklabelcolor   = INK_SOFT,
    yticklabelcolor   = INK_SOFT,
    xtickcolor        = INK_SOFT,
    ytickcolor        = INK_SOFT,
    backgroundcolor   = PAGE_BG,
    topspinevisible   = false,
    rightspinevisible = false,
    leftspinecolor    = INK_SOFT,
    bottomspinecolor  = INK_SOFT,
    xgridvisible      = false,
    ygridvisible      = true,
    ygridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.12),
    yminorgridvisible = false,
)

barplot!(
    ax, x, height;
    stack       = stack,
    color       = stack,
    colormap    = IMPRINT_PALETTE[1:n_product],
    width       = 0.6,
    strokewidth = 0,
)

ax.xticks = (1:n_quarter, quarters)

# --- Total labels: genuinely bold and larger than any other text, directly
# above the tallest segment of each stack. `rich()` mixes weight/size within
# one label -- the dollar figure is bold and oversized, the trailing "M"
# unit is smaller and softer, echoing typographic hierarchy from financial
# dashboards.
for (i, total) in enumerate(totals)
    text!(
        ax, Point2f(i, total);
        text   = rich(
            rich("\$$(round(total, digits = 1))"; font = :bold, fontsize = 19, color = INK),
            rich("M"; fontsize = 14, color = INK_SOFT),
        ),
        offset = (0, 8),
        align  = (:center, :bottom),
    )
end

Legend(
    fig[1, 2], [PolyElement(color = c) for c in IMPRINT_PALETTE[1:n_product]], product_lines;
    labelcolor      = INK_SOFT,
    labelsize       = 13,
    framevisible    = false,
    backgroundcolor = PAGE_BG,
)

# Fix the y-range last so the label headroom above the tallest bar survives
# any autolimits reset triggered by the legend/text calls above.
ylims!(ax, 0, maximum(totals) * 1.16)

# --- Save ---------------------------------------------------------------
save("plot-$(THEME).png", fig; px_per_unit = 2)

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/bar-stacked-labeled/makie/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "bar-stacked-labeled",
  "language": "julia",
  "library": "makie",
  "page": "https://anyplot.ai/bar-stacked-labeled/julia/makie",
  "hub": "https://anyplot.ai/bar-stacked-labeled",
  "code_json": "https://api.anyplot.ai/specs/bar-stacked-labeled/makie/code",
  "spec_json": "https://api.anyplot.ai/specs/bar-stacked-labeled",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/bar-stacked-labeled/julia/makie/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/bar-stacked-labeled/julia/makie/plot-dark.png",
  "quality_score": 90.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Stacked Bar Chart with Total Labels on anyplot.ai.

Other implementations