svgspider
Spider plot
How steeply does the output respond as each input moves away from its base value?
How to read it
- Read each line as the output as one input moves from base.
- Steeper means more sensitive.
- All lines cross at the base case.
- Callout 1: A steep line: a sensitive input.
- Callout 2: The base case.
- Callout 3: This input lowers the output as it rises.
Watch out
- A percent change isn't equally likely for every input, so steepness alone doesn't rank risks.
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.
- Changes within ±2 are read as fractions (−0.2 = −20%), larger values as percent; the dashed line is the output at zero change.
# Spider plot — Codesplash Chart Lab (recipe "spider")
# 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("spider-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
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)))
CH = "change from base"
K = "NPV ($k)"
INPUT = "input"
groups = levels_of(df[INPUT]) if INPUT else [None]
series = []
for name in groups:
d = df if name is None else df[df[INPUT].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[CH]).sort_values(CH)))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axvline(0, color="grey", linewidth=0.8)
for i, (name, d) in enumerate(series):
ax.plot(d[CH], d[K], marker="o", ms=4, color=PALETTE[i % len(PALETTE)], linewidth=1.8, label=name)
ax.set_xlabel(CH)
ax.set_ylabel(K)
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads spider-demo.csv · app theme from the optional codesplash helper
# Spider plot — Codesplash Chart Lab (recipe "spider")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("spider-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
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)))
CH = "change from base"
K = "NPV ($k)"
INPUT = "input"
groups = levels_of(df[INPUT]) if INPUT else [None]
series = []
for name in groups:
d = df if name is None else df[df[INPUT].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[CH]).sort_values(CH)))
fig = go.Figure()
for i, (name, d) in enumerate(series):
fig.add_scatter(x=d[CH], y=d[K], mode="lines+markers", name=name, line=dict(color=PALETTE[i % len(PALETTE)]))
fig.update_layout(xaxis_title=CH, yaxis_title=K)
fig.show()Needs pandas, numpy, plotly · reads spider-demo.csv · app theme from the optional codesplash helper
# Spider plot — Codesplash Chart Lab (recipe "spider")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("spider-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["input"]] <- factor(df[["input"]])
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
ch_col <- "change from base"
k_col <- "NPV ($k)"
input_col <- "input"
d <- data.frame(ch = df[[ch_col]], k = df[[k_col]], input = factor(as.character(df[[input_col]]), levels = levels_of(df[[input_col]])))
p <- ggplot(d[order(d$ch), ], aes(ch, k, colour = input)) + geom_vline(xintercept = 0, colour = "grey60") +
geom_line(linewidth = 0.9) + geom_point(size = 1.6) + scale_colour_manual(values = cs_cat) +
labs(x = ch_col, y = k_col, colour = NULL) + theme_cs
print(p)Needs ggplot2 · reads spider-demo.csv · app theme from the optional codesplashr helper