Skip to content
svgarm-share

Arm shares

How quickly does each policy shift its plays toward the best arm?

Demo data · seed 20261101 · 408 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each panel as one policy's share of plays per arm over rounds.
  2. A policy that shifts quickly to one arm is exploiting early.
  3. Compare how soon the best arm's band takes over.
  1. Callout 1: The best arm's share grows.
  2. Callout 2: Early: exploring all arms.

Watch out

  • Very fast convergence can lock on to a wrong arm if rewards change.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Shares are renormalized to sum to 1 at each round; long series are thinned to about 400 rounds per panel.
# Arm shares — Codesplash Chart Lab (recipe "arm-share")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import to_rgba

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_HATCHES = ["", "////", "..", "\\\\\\\\", "---", "xx", "|||", "++"]
HATCH_INK = to_rgba(plt.rcParams["axes.facecolor"], 0.5)  # stripes let the chart surface show through

df = pd.read_csv("arm-share-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["arm"] = pd.Categorical(df["arm"].astype("string"), categories=["A (4.0%)", "B (4.6%)", "C (5.1%)", "D (6.0%)"])
df["policy"] = pd.Categorical(df["policy"].astype("string"), categories=["UCB1", "Thompson sampling"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
T = "round"
S = "share of plays"
ARM = "arm"
POL = "policy"
policies = levels_of(df[POL]) if POL else [None]
arms = levels_of(df[ARM])
fig, axes = plt.subplots(1, len(policies), figsize=(4 * len(policies) + 1, 3.8), sharey=True, squeeze=False)
for ax, pol in zip(axes[0], policies):
    d = df if pol is None else df[df[POL].astype(str) == str(pol)]
    wide = d.pivot_table(index=T, columns=ARM, values=S, aggfunc="sum", observed=False).reindex(columns=arms).fillna(0)
    wide = wide.div(wide.sum(axis=1).replace(0, 1), axis=0)  # shares sum to 1
    ax.stackplot(wide.index, wide.T.values, colors=PALETTE[: len(arms)], labels=[str(a) for a in arms], alpha=0.85,
                 hatch=[SERIES_HATCHES[i % 8] for i in range(len(arms))], hatchcolor=HATCH_INK, linewidth=0)  # texture per arm, as in the app
    ax.set_title(str(pol) if pol is not None else "", fontsize=10, loc="left")
    ax.set_xlabel(T)
axes[0, 0].set_ylabel("share of plays")
axes[0, 0].legend(fontsize=8, loc="lower left")
plt.show()

Needs pandas, numpy, matplotlib · reads arm-share-demo.csv · app theme from the optional codesplash helper