Skip to content
svgcld-plot

Compact letter display

Which groups differ from which, at a glance?

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

How to read it

  1. Read each group's centre and interval.
  2. Read the letters: the post hoc test could not separate groups that share a letter.
  3. Groups with no letters in common are.
  1. Callout 1: The letter above each group.
  2. Callout 2: Sharing a letter: the test could not separate them.
  3. Callout 3: Letters are ordered by group, not by size.

Watch out

  • Sharing a letter doesn't mean equal: it means the test couldn't separate them.

Defaults

Sort by the centre (highest first)
Off
Sort groups from the highest centre to the lowest.

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing statistical.
  • Letters come from the post hoc comparisons (Piepho's insert-and-absorb algorithm): two groups that share any letter are not significantly different at α.
  • Intervals are each group's own t interval for its mean, not the simultaneous intervals of the comparisons — the letters, not overlapping bars, carry the test.
  • Groups keep the engine's level order unless sorted; letters are assigned from the first level, so sorting does not relabel them.
# Compact letter display — Codesplash Chart Lab (recipe "cld-plot")
# controls: sort=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

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"]

df = pd.read_csv("cld-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["feed"] = pd.Categorical(df["feed"].astype("string"), categories=["horsebean", "linseed", "soybean", "meatmeal", "casein", "sunflower"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
LABEL = "feed"
C = "mean weight (g)"
LO = "lower"
HI = "upper"
LET = "letters"
SORT = False  # order groups by their centre
d = df.dropna(subset=[LABEL, C]).reset_index(drop=True)
if SORT:
    d = d.sort_values(C).reset_index(drop=True)
x = np.arange(len(d))
top = d[HI] if HI else d[C]
fig, ax = plt.subplots(figsize=(8, 4.5))
if LO and HI:
    ax.errorbar(x, d[C], yerr=[d[C] - d[LO], d[HI] - d[C]], fmt="none", ecolor=PALETTE[0], capsize=3, linewidth=1.3)
ax.scatter(x, d[C], s=46, color=PALETTE[0], zorder=3)
pad = 0.04 * float(top.max() - (d[LO] if LO else d[C]).min() or 1)
for i, row in d.iterrows():  # groups sharing a letter do not differ significantly
    ax.text(i, top[i] + pad, str(row[LET]), ha="center", va="bottom", fontsize=10, fontweight="bold", color=REF)
ax.set_xticks(x, d[LABEL].astype(str))
ax.set_ylabel(C)
ax.margins(y=0.12)
plt.show()

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