Gauge Charts and KPI Cards in Plotly with go.Indicator

Make gauge charts, big-number KPI cards with up and down deltas, bullet charts and sparkline cards in Plotly using go.Indicator.

Plotly draws gauges and KPI cards with go.Indicator. Set mode="gauge+number" for a gauge chart, mode="number+delta" for a big number with its change, and use gauge={...} to set the axis range, colored bands, and a target line.

Quick Example

A gauge for a made-up hotel's occupancy rate:

import plotly.graph_objects as go

fig = go.Figure(go.Indicator(
    mode="gauge+number+delta",
    value=78,
    number=dict(suffix="%"),
    delta=dict(reference=71, suffix=" pts"),
    title=dict(text="Occupancy this month"),
    gauge=dict(
        axis=dict(range=[0, 100], ticksuffix="%"),
        bar=dict(color="#1e3a8a", thickness=0.3),
        steps=[dict(range=[0, 60], color="#fee2e2"),
               dict(range=[60, 80], color="#fef3c7"),
               dict(range=[80, 100], color="#dcfce7")],
        threshold=dict(value=85, thickness=0.85, line=dict(color="#dc2626", width=4)),
    ),
))
fig.update_layout(height=360, margin=dict(l=40, r=40, t=80, b=20))
fig.show()

Plotly gauge chart showing 78 percent hotel occupancy, 7 points above last month, with shaded bands and a red target line at 85

The dark bar reaches 78, the red threshold line marks a target of 85, and the delta underneath shows a 7 point rise from 71. There's no Plotly Express version of this chart. The code targets Plotly 6.x.

The parts of an indicator:

mode piece Draws Configure with
number The value as large text number=dict(prefix, suffix, valueformat, font)
delta The change from a reference delta=dict(reference, relative, valueformat, position)
gauge A dial or bar gauge=dict(shape, axis, bar, steps, threshold)

Big Number KPI

valueformat uses d3 format strings: ",.0f" for thousands separators, ".3s" for 1.28M style, ".1%" for fractions.

fig = go.Figure(go.Indicator(
    mode="number",
    value=1_284_500,
    number=dict(prefix="$", valueformat=".3s", font=dict(size=90, color="#0f766e")),
    title=dict(text="Revenue, year to date"),
))
fig.update_layout(width=600, height=250, margin=dict(l=20, r=20, t=60, b=20))
fig.show()

A large teal number reading 1.28 million dollars under the title Revenue, year to date

Show the Change with delta

The delta is value - reference. Set relative=True to show the percent change instead. Increases are green with an up triangle and decreases red with a down triangle, so swap the colors for metrics where lower is better.

fig = go.Figure()
fig.add_trace(go.Indicator(
    mode="number+delta", value=342,
    delta=dict(reference=300, relative=True, valueformat=".1%"),
    title=dict(text="Bookings (up is good)"),
    domain=dict(x=[0, 0.5], y=[0, 1]),
))
fig.add_trace(go.Indicator(
    mode="number+delta", value=6.1,
    number=dict(suffix="%"),
    delta=dict(reference=8.4, suffix=" pts", valueformat=".1f",
               increasing=dict(color="#dc2626"), decreasing=dict(color="#16a34a")),
    title=dict(text="Cancellations (down is good)"),
    domain=dict(x=[0.5, 1], y=[0, 1]),
))
fig.update_layout(width=700, height=260, margin=dict(l=20, r=20, t=70, b=20))
fig.show()

Two KPI numbers: bookings up 14 percent in green and cancellations down 2.3 points, also in green

If you leave out reference, it defaults to the current value and the delta is zero. domain gives each indicator its own part of the figure, as fractions from 0 to 1.

A Row of KPI Cards

Loop over your metrics and give each indicator a slice of the figure with domain. Background rectangles in paper coordinates make them look like cards.

kpis = [
    # title, value, last month, number format, delta format, lower is better
    ("Revenue", 214_800, 198_300, dict(prefix="$", valueformat=".3s"), ".1%", False),
    ("Bookings", 342, 300, dict(valueformat=",d"), ".1%", False),
    ("Cancel rate", 0.061, 0.084, dict(valueformat=".1%"), ".1%", True),
    ("Guest rating", 4.6, 4.5, dict(valueformat=".1f"), ".1%", False),
]
gap = 0.02
width = (1 - gap * (len(kpis) - 1)) / len(kpis)

fig = go.Figure()
for i, (title, value, previous, number, delta_format, lower_is_better) in enumerate(kpis):
    left = i * (width + gap)
    good, bad = "#16a34a", "#dc2626"
    up, down = (bad, good) if lower_is_better else (good, bad)
    fig.add_trace(go.Indicator(
        mode="number+delta", value=value,
        number={**number, "font": dict(size=34)},
        delta=dict(reference=previous, relative=True, valueformat=delta_format,
                   increasing=dict(color=up), decreasing=dict(color=down)),
        title=dict(text=title, font=dict(size=15, color="#475569")),
        domain=dict(x=[left, left + width], y=[0.12, 0.72]),
    ))
    fig.add_shape(type="rect", xref="paper", yref="paper", x0=left, x1=left + width,
                  y0=0, y1=1, fillcolor="#f1f5f9", line_width=0, layer="below")

fig.update_layout(height=220, margin=dict(l=10, r=10, t=10, b=10))
fig.show()

Row of four KPI cards for revenue, bookings, cancellation rate and guest rating, each with its change from last month

relative=True is a percent change even when the metric is itself a percentage: the cancel rate fell 2.3 points, which is a 27% drop. Label which one you're showing.

Bullet Chart

gauge=dict(shape="bullet") flattens the gauge into a horizontal bar, which fits many metrics in little space. The title sits to the left, so leave room with the domain's x start.

rows = [("Occupancy %", 78, 85, 100), ("Direct bookings %", 46, 40, 100),
        ("Room rate $", 182, 190, 250)]

fig = go.Figure()
for i, (name, value, target, top) in enumerate(rows):
    y0 = 1 - (i + 1) / len(rows) + 0.07
    fig.add_trace(go.Indicator(
        mode="gauge+number", value=value,
        title=dict(text=name, font=dict(size=14)),
        number=dict(font=dict(size=24)),
        domain=dict(x=[0.25, 1], y=[y0, y0 + 0.19]),
        gauge=dict(
            shape="bullet", axis=dict(range=[0, top]),
            bar=dict(color="#0f172a", thickness=0.35),
            steps=[dict(range=[0, target * 0.8], color="#cbd5e1"),
                   dict(range=[target * 0.8, top], color="#e2e8f0")],
            threshold=dict(value=target, thickness=0.8, line=dict(color="#ea580c", width=4)),
        ),
    ))
fig.update_layout(width=800, height=280, margin=dict(l=10, r=20, t=20, b=20))
fig.show()

Three bullet charts: occupancy 78 against a target of 85, direct bookings 46 against 40, and room rate 182 against 190

Direct bookings is past its orange target line; occupancy and room rate are short of theirs.

Several Gauges with make_subplots

Gauges can also go in subplots with the type "indicator":

from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=3, specs=[[{"type": "indicator"}] * 3],
                    horizontal_spacing=0.12)
for col, (hotel, score) in enumerate([("Harbor", 91), ("Midtown", 74), ("Airport", 58)], 1):
    color = "#16a34a" if score >= 80 else "#d97706" if score >= 65 else "#dc2626"
    fig.add_trace(go.Indicator(
        mode="gauge+number", value=score, title=dict(text=hotel),
        gauge=dict(axis=dict(range=[0, 100]), bar=dict(color=color, thickness=1),
                   bgcolor="#f1f5f9", borderwidth=0),
    ), row=1, col=col)
fig.update_layout(width=800, height=280, margin=dict(l=40, r=40, t=60, b=10),
                  title="Cleanliness score by hotel")
fig.show()

Three gauges for cleanliness score: Harbor 91 in green, Midtown 74 in amber and Airport 58 in red

Here thickness=1 makes the bar fill the whole arc, giving a donut-style gauge.

KPI Card with a Sparkline

An indicator can share a figure with ordinary traces. Hide the axes and keep the line in the bottom part of the card.

import numpy as np
import pandas as pd

rng = np.random.default_rng(109)
daily = pd.Series(np.linspace(9, 13, 60) + rng.normal(0, 0.9, 60),
                  index=pd.date_range("2026-09-01", periods=60)).round().astype(int)
last_30, prior_30 = daily[-30:].sum(), daily[:-30].sum()

fig = go.Figure()
fig.add_trace(go.Scatter(x=daily.index, y=daily, mode="lines", fill="tozeroy",
                         line=dict(color="#7c3aed", width=2),
                         fillcolor="rgba(124, 58, 237, 0.12)",
                         hovertemplate="%{x|%b %d}: %{y} bookings<extra></extra>"))
fig.add_trace(go.Indicator(
    mode="number+delta", value=last_30,
    delta=dict(reference=prior_30, relative=True, valueformat=".1%"),
    title=dict(text="Bookings, last 30 days"),
    domain=dict(x=[0, 1], y=[0.45, 0.85]),
))
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False, domain=[0, 0.32])
fig.update_layout(width=420, height=300, template="plotly_white",
                  margin=dict(l=20, r=20, t=20, b=20))
fig.show()

KPI card with the bookings total for the last 30 days, its percent change and a purple sparkline underneath

Limitations and Alternatives

  • No needle. go.Indicator has a value bar and a threshold line only. For a speedometer needle, set bar=dict(thickness=0) and use the threshold at the value as a marker.
  • No click or hover text on the indicator. Put context in the title.
  • Small screens. Indicators in one row shrink together and can get cramped. In a dashboard, make each card its own figure and let the page wrap them.

In Streamlit, st.metric gives you the same number-and-delta card without any layout work; see the Streamlit KPI dashboard.

Gauge, Bullet, or Number?

A plain number with a delta answers "what is it and which way is it moving" in the least space. Use a bullet chart when each metric has a target and you have several to compare. A gauge takes the most room, so save it for one headline metric with a fixed range.

Similar Topics