svgbrushablezoom-overview
Zoom with overview
How do I explore a long series in detail without losing the big picture?
How to read it
- Use the strip at the bottom to see the whole series.
- Drag the window on the strip to choose the detail above.
- Check the date range and point count in the corner.
- Callout 1: Detail: the selected window.
- Callout 2: The draggable window on the overview.
- Callout 3: The selected range and its point count.
Watch out
- The detail's y axis rescales to the window, so moves look larger than they are.
Defaults
- Initial window (days)
- 180
- How much of the series the detail view shows when it opens.
- Range 7 to 3,650, step 1
- Fill under the line
- On
- Shade the area under the line.
Pinned in the code
- Drag on the overview to choose the detail window, drag the window to pan, click outside it to recentre, double-click to show everything.
- The detail y axis rescales to the visible points; the overview always shows the full range (thinned to ≈ 2 points per pixel).
- The window starts at the last N days of the series (control). Exports show the chart in its current window.
- All calendar arithmetic is in UTC; timestamps are epoch milliseconds.
# Zoom with overview — Codesplash Chart Lab (recipe "zoom-overview")
# controls: initialDays=180, area=true
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("zoom-overview-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["date"] = pd.to_datetime(df["date"])
_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")
d = df.dropna(subset=["date", "close"]).sort_values("date")
end = d["date"].max()
start = end - pd.Timedelta(days=180) # the detail window starts at the last N days
win = d[d["date"] >= start]
fig, (ax, ov) = plt.subplots(2, 1, figsize=(8, 5), gridspec_kw={"height_ratios": [3, 1]})
ax.plot(win["date"], win["close"], color=PALETTE[0], linewidth=1.4) # detail y rescales to the window
ax.fill_between(win["date"], win["close"].min(), win["close"], color=PALETTE[0], alpha=0.15, linewidth=0)
ov.plot(d["date"], d["close"], color=REF, linewidth=0.8) # overview: the full range
ov.axvspan(start, end, color=PALETTE[0], alpha=0.2)
ax.set_ylabel("close")
ov.set_yticks([])
plt.show()Needs pandas, numpy, matplotlib · reads zoom-overview-demo.csv · app theme from the optional codesplash helper
# Zoom with overview — Codesplash Chart Lab (recipe "zoom-overview")
# controls: initialDays=180, area=true
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("zoom-overview-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["date"] = pd.to_datetime(df["date"])
d = df.dropna(subset=["date", "close"]).sort_values("date")
end = d["date"].max()
start = end - pd.Timedelta(days=180)
fig = go.Figure(go.Scatter(x=d["date"], y=d["close"], mode="lines", line_color=PALETTE[0], fill="tozeroy"))
# plotly's range slider is the overview; drag it to choose the detail window
fig.update_xaxes(range=[start, end], rangeslider_visible=True)
fig.update_yaxes(autorange=True, fixedrange=False, title_text="close")
fig.show()Needs pandas, numpy, plotly · reads zoom-overview-demo.csv · app theme from the optional codesplash helper
# Zoom with overview — Codesplash Chart Lab (recipe "zoom-overview")
# controls: initialDays=180, area=true
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("zoom-overview-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["date"]] <- as.POSIXct(df[["date"]], tz = "UTC")
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
arrange <- function(plots, layout, widths = NULL, heights = NULL) {
# layout: matrix of plot indices (NA = empty cell). patchwork aligns the panels when it is
# installed; otherwise base grid viewports place the plots (axes may not line up exactly).
widths <- if (is.null(widths)) rep(1, ncol(layout)) else widths
heights <- if (is.null(heights)) rep(1, nrow(layout)) else heights
if (requireNamespace("patchwork", quietly = TRUE)) {
design <- paste(apply(layout, 1, function(r) paste(ifelse(is.na(r), "#", LETTERS[r]), collapse = "")), collapse = "\n")
print(patchwork::wrap_plots(plots, design = design, widths = widths, heights = heights, guides = "collect"))
return(invisible())
}
grid::grid.newpage()
grid::pushViewport(grid::viewport(layout = grid::grid.layout(nrow(layout), ncol(layout),
widths = grid::unit(widths, "null"), heights = grid::unit(heights, "null"))))
for (i in seq_along(plots)) {
at <- which(layout == i, arr.ind = TRUE)
print(plots[[i]], vp = grid::viewport(layout.pos.row = unique(at[, 1]), layout.pos.col = unique(at[, 2])))
}
}
d <- df[!is.na(df[["date"]]) & !is.na(df[["close"]]), , drop = FALSE]
d <- d[order(d[["date"]]), , drop = FALSE]
end <- max(d[["date"]]); start <- end - 180 * 86400 # the last N days
win <- d[d[["date"]] >= start, , drop = FALSE]
detail <- ggplot(win, aes(.data[["date"]], .data[["close"]])) +
geom_ribbon(aes(ymin = min(.data[["close"]]), ymax = .data[["close"]]), fill = cs_cat[1], alpha = 0.15) +
geom_line(colour = cs_cat[1]) + labs(x = NULL, y = "close") + theme_cs
overview <- ggplot(d, aes(.data[["date"]], .data[["close"]])) +
annotate("rect", xmin = start, xmax = end, ymin = -Inf, ymax = Inf, fill = cs_cat[1], alpha = 0.2) +
geom_line(colour = ref_col, linewidth = 0.3) + labs(x = NULL, y = NULL) +
theme_cs + theme(axis.text.y = element_blank())
arrange(list(detail, overview), layout = matrix(1:2, 2), heights = c(3, 1))Needs ggplot2 · reads zoom-overview-demo.csv · app theme from the optional codesplashr helper
-- Zoom with overview — Codesplash Chart Lab (recipe "zoom-overview")
-- controls: initialDays=180, area=true
-- the detail window: the last 180 days of the series (the overview is the full table)
SELECT "date", "close"
FROM read_csv('zoom-overview-demo.csv')
WHERE "close" IS NOT NULL
AND "date" >= (SELECT max("date") FROM read_csv('zoom-overview-demo.csv')) - INTERVAL 180 DAY
ORDER BY "date";Needs duckdb · reads zoom-overview-demo.csv