Skip to content
svgtrend-plot

Ordered trend

Do the groups move in the expected order (a trend or an umbrella)?

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

How to read it

  1. Read the groups in their declared order.
  2. Read the line through them: the fitted order.
  3. Compare the trend with the intervals: is the rise larger than each group's uncertainty?
  1. Callout 1: The first group in order.
  2. Callout 2: The group means follow this line.
  3. Callout 3: The last group in order.

Watch out

  • Declare the order before looking at the data. An order chosen from the data invalidates the test.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing inferential.
  • Groups keep the order declared in the analysis (`order`), which the ordered test assumed — never re-sorted by value.
  • The dashed line is the engine's fitted trend (e.g. isotonic fit or rank-based slope); an umbrella fit peaks at the declared or estimated peak.
# Ordered trend — Codesplash Chart Lab (recipe "trend-plot")
# controls: defaults
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("trend-plot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["dose"] = pd.Categorical(df["dose"].astype("string"), categories=["0 mg", "5 mg", "10 mg", "20 mg", "40 mg"])

_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")
def first(col):
    """The first finite value of a column the engine repeats on every row (None if absent)."""
    if col is None:
        return None
    v = pd.to_numeric(df[col], errors="coerce").dropna()
    return float(v.iloc[0]) if len(v) else None
LABEL = "dose"
EST = "median"
LO = "low"
HI = "high"
NOTE = None
FIT = "fitted trend"
LOG = False
d = df.dropna(subset=[EST]).drop_duplicates(subset=[LABEL]).reset_index(drop=True)
pos = np.arange(len(d))
fig, ax = plt.subplots(figsize=(8, 4.5))
zone = None
if zone is not None:
    ax.axhspan(*zone, color="#19966e", alpha=0.1, lw=0)
ax.plot(pos, d[EST], color=GREY, linewidth=1)
if FIT and d[FIT].notna().all():
    ax.plot(pos, d[FIT], color=PALETTE[1], linestyle="--", linewidth=1.8, label="fitted")
colors = d["_color"] if "_color" in d else [PALETTE[0]] * len(d)
for i, row in d.iterrows():
    lo, hi = (row[LO], row[HI]) if LO and HI else (np.nan, np.nan)
    ax.errorbar(pos[i], row[EST], yerr=[[row[EST] - lo], [hi - row[EST]]] if np.isfinite(lo) else None, fmt="o", color=colors[i], capsize=3)
    note = row.get("_note") if "_note" in d else (row[NOTE] if NOTE and pd.notna(row.get(NOTE)) else None)
    if note is not None and note == note:
        txt = note if isinstance(note, str) else ("p < .001" if note < 0.001 else f"p = {note:.3f}".replace("0.", "."))
        ax.annotate(txt, (pos[i], hi if np.isfinite(hi) else row[EST]), textcoords="offset points", xytext=(0, 6), ha="center", fontsize=8, color=REF)
ax.set_xticks(pos, d[LABEL].astype(str))
ax.set_ylabel("centre")
if LOG:
    ax.set_yscale("log")
plt.show()

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