isocline-plot

中文文档
0.1.0发布于 2026/11/04MITTypeScriptES Module零依赖

Observable Plot visualization layer for isocline results

原始使用文档
文档目录12 节
  1. Install
  2. Quick start
  3. Chart families
  4. Forecast - forecastPlot / forecastMarks
  5. Anomalies - anomalyPlot / anomalyMarks
  6. Decomposition - decomposePlot
  7. Seasonality - seasonalityPlot
  8. Changepoints - changepointPlot / changepointMarks
  9. Backtest - backtestPlot + backtestWinner
  10. Composition
  11. Theme and formatting
  12. Design notes

isocline-plot

Observable Plot visualization layer for isocline results. Every chart family comes in two forms:

  • *Marks(series, result, opts?) → { marks: Plot.Markish[], plotOptions }
    • composable marks plus partial plot options, for building your own Plot.plot({...plotOptions, marks}).
  • *Plot(...) → a rendered HTMLElement (a Plot.plot figure with the isocline theme applied), ready to append to the DOM.

The package has a single peer dependency, @observablehq/plot ^0.6, and no runtime dependency on isocline - it imports only the result types, so it renders any object matching the contract shape (mocked data included). When series.t (epoch-millis) is present the x axis is temporal; otherwise the index is used and labeled "index".

Install

npm install isocline-plot @observablehq/plot

Quick start

import * as PP from "isocline-plot";
import { loadIsocline, genSeries } from "isocline";

const iso = await loadIsocline();
const { y, t } = genSeries({ n: 720, period: 24 });
const fc = iso.forecast({ y, t }, { horizon: 48 });

document.body.appendChild(PP.forecastPlot({ y, t }, fc, {
  showBand: true,        // PI band (default true)
  showComponents: false, // projected trend/seasonal lines when present
  paths: false,          // spaghetti of bootstrap sample paths
  height: 320,
  yLabel: "value",
}));

Chart families

Forecast - forecastPlot / forecastMarks

History (cyan), point forecast (violet dashed), PI band (violet, 15% opacity), a rule at the split point, an end-point dot; optional projected trend/seasonal component lines and up to 60 drawn bootstrap sample paths.

PP.forecastPlot(series, forecast, {
  paths: true,          // default false
  showComponents: true, // default false
  showBand: true,       // default true
  height: 320,          // default 320
  width: 800,           // optional (fluid when omitted)
  xLabel: "time",       // default "time"/"index" by input kind
  yLabel: "value",      // default "value"
  title: "48h forecast",
});
OptionTypeDefaultDescription
pathsbooleanfalseDraw bootstrap sample paths (spaghetti)
showComponentsbooleanfalseDraw projected trend (amber dashed) and seasonal (green) when the result has them
showBandbooleantrueDraw the prediction-interval band
heightnumber320Plot height in px
widthnumber-Plot width (fluid when omitted)
xLabelstring"time" / "index"X axis label
yLabelstring"value"Y axis label
titlestring-Figure caption (<title> on the SVG)

Anomalies - anomalyPlot / anomalyMarks

Series line plus flagged points: spikes as red up-triangles, dips as blue down-triangles, an amber dashed expected line, and tooltips with index, observed, expected, and score.

PP.anomalyPlot(series, anomalyResult, {
  showExpected: true, // default true
  height: 320,
  yLabel: "value",
});
PP.anomalySplit(anomalyResult); // { spikes: number, dips: number } for legends
OptionTypeDefaultDescription
showExpectedbooleantrueDraw the expected-value line
height / width / xLabel / yLabelnumber / stringas forecastLayout and axis labels

Decomposition - decomposePlot

Three vertically stacked rows (trend, seasonal, residual) with per-row independent y scales; the seasonal row caption includes seasonalStrength.

PP.decomposePlot(series, decomposeResult, {
  height: 150, // per row, default 150
  width: 800,
  xLabel: "time", // label on the bottom row only
});

Seasonality - seasonalityPlot

ACF (lollipop with 95% confidence band) and periodogram (power vs period, log x) side by side, best period highlighted on both panels.

PP.seasonalityPlot(seasonalityResult, { height: 260, width: 400 }); // width is per panel
PP.seasonalityCandidates(seasonalityResult); // candidate chips data

Changepoints - changepointPlot / changepointMarks

Series line, amber step line of segment means, vertical dashed rules at each changepoint, and tooltips showing #index, μ before → after.

PP.changepointPlot(series, changepointResult, { height: 320, yLabel: "value" });

Backtest - backtestPlot + backtestWinner

A models × metrics heatmap (Plot.cell) over rmse / mae / smape / coverage, rank-colored (violet→cyan, best model on top row), with formatted values in each cell.

const el = PP.backtestPlot(backtestResult, { height: 220 });
document.body.appendChild(el);
PP.backtestWinner(backtestResult); // model name with lowest RMSE, e.g. "stl_ets"

Composition

The *Marks forms return { marks, plotOptions }. plotOptions starts from isoclineTheme (margins, mono font, muted tick color, grid defaults) and includes the axis scales; spread it first and override anything:

import * as Plot from "@observablehq/plot";
import * as PP from "isocline-plot";

const { marks, plotOptions } = PP.forecastMarks(series, fc, { yLabel: "kW" });
const fig = Plot.plot({
  ...plotOptions,       // theme + axes
  y: { ...plotOptions.y, domain: [0, 100] }, // your overrides
  marks,
});
document.body.appendChild(fig);

Theme and formatting

  • isoclineTheme - shared Partial<Plot.PlotOptions>: dark-transparent background (the page provides the panel), muted ticks, grid on the y axis, mono font at 10.5px.
  • C - the color tokens: cyan #22d3ee, violet #a78bfa, amber #fbbf24, red #f87171, blue #60a5fa, green #34d399, ink #e6edf3, muted #8b98a9, grid rgba(255,255,255,.07), plus panel colors.
  • fmt(x) - 3-significant-digit number formatter used across all plots ("1.23", "12.3", "1,234", exponential outside [1e-3, 1e6)).
  • MONO - the mono font stack; applyIsoclineCss() idempotently injects the small stylesheet (grid/axis colors) that the *Plot forms call for you.
  • plot(spec) - thin wrapper that renders Plot.plot(spec) with the isocline-plot class attached.

Design notes

decomposePlot and seasonalityPlot render multiple separate plots in one container rather than a single faceted plot. This is deliberate: Plot facets share scales across rows, which would crush the near-zero residual row against a large trend range. Independent per-row y scales (and independent x scales for the ACF/periodogram panels) keep every component readable. The tradeoff is that rows are separate SVGs with slightly different pixel widths on fluid layouts.

Both functions are *Plot-only (no *Marks form) because their multi-plot structure cannot be expressed as a single mark list.

版本与发布记录

isocline-plot 共发布 2 个版本,首次发布于 2026/11/04;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.0latest2026/11/041 天前
0.0.0-stage2026/11/041 天前

关于 isocline-plot 的常见问题

isocline-plot 是什么?

Observable Plot visualization layer for isocline results

如何安装 isocline-plot?

在项目目录运行 npm install isocline-plot,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:isocline(^0.1.0)、@observablehq/plot(^0.6.17)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

isocline-plot 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

isocline-plot 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

isocline-plot 可以商用吗?

isocline-plot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

isocline-plot 还在维护吗?

最新版本 0.1.0 发布于 2026/11/04(1 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/11/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。