See rank changes at a glance with a slopegraph

Visualize

See rank changes at a glance with a slopegraph

Created: Last updated: Read time: 1 min

When comparing products year over year, a slopegraph connects two time points with lines. It conveys rank and change size at the same time.

import matplotlib.pyplot as plt
import numpy as np

brands = ["Service A", "Service B", "Service C", "Service D", "Service E"]
score_2023 = np.array([62, 55, 48, 44, 38])
score_2024 = np.array([75, 58, 64, 40, 42])
colors = plt.cm.Blues(np.linspace(0.4, 0.8, len(brands)))

fig, ax = plt.subplots(figsize=(6, 4))
for idx, name in enumerate(brands):
    ax.plot(
        [0, 1],
        [score_2023[idx], score_2024[idx]],
        color=colors[idx],
        linewidth=2.5,
    )
    ax.scatter([0, 1], [score_2023[idx], score_2024[idx]], color=colors[idx], s=60)
    ax.text(
        -0.05,
        score_2023[idx],
        f"{name} {score_2023[idx]:.0f}",
        ha="right",
        va="center",
    )
    ax.text(
        1.05,
        score_2024[idx],
        f"{score_2024[idx]:.0f}",
        ha="left",
        va="center",
    )

ax.set_xticks([0, 1], labels=["2023", "2024"])
ax.set_title("NPS change for key services (points)")
ax.set_ylim(30, 80)
ax.spines[["top", "right", "bottom"]].set_visible(False)
ax.tick_params(left=False, bottom=False)
ax.set_yticks([])
ax.grid(axis="y", alpha=0.15)

fig.tight_layout()

plt.show()

Rank and change size are visible at the same time.

Reading tips #

  • Height shows the score at each time point; slope shows growth or decline.
  • Crossing lines indicate rank reversals, worth highlighting in commentary.
  • Sorting by change size can emphasize movement.