@danielsimonjr/ mathts-plot 页面存档备份,存于互联网档案馆
无头 SVG 2D/3D 绘图 数学。 。 。 .
纯函数返回自成一体的 SVG 字符串——没有浏览器,没有画布,没有运行时间
数学和科学基础以外的依赖性(core编号 :functions编号 :expression) (中文(简体) ). 每个函数
强迫其输入, 绝不投出错误数据: 空, NaN,或 Infinity 输入为 a
"没有数据"的占位符 SVG 而不是崩溃. 见
docs/superpowers/specs/2026-07-07-plotting-design.md 为设计.
安装
npm install @danielsimonjr/mathts-plot
使用量
下方的每个函数返回自成一体的 SVG 字符串(<svg ...>...</svg>)——使它成为
直接在一个 <img src="data:image/svg+xml,...">写给 .svg 文件,或丢弃它
输入 HTML.
line - 一个系列,或与其它系列重叠
import { line } from '@danielsimonjr/mathts-plot';
const svg = line([0, 1, 2, 3], [0, 1, 4, 9], { title: 'squares', xLabel: 'x', yLabel: 'y' });
// svg === '<svg ...>...</svg>'
overlay ——在共享的自动缩放轴上结合多层
import { overlay } from '@danielsimonjr/mathts-plot';
const svg = overlay(
[
{ type: 'line', x: [0, 1, 2], y: [0, 1, 2], label: 'model' },
{ type: 'scatter', x: [0, 1, 2], y: [0.1, 1.2, 1.8], label: 'data' },
],
{ legend: true }
);
surface 3D 表面通过正图投影 + 画家算法
import { surface } from '@danielsimonjr/mathts-plot';
const z = [
[0, 1, 2],
[1, 2, 3],
[2, 3, 4],
]; // z[row][col]
const svg = surface(z, { kind: 'filled', azim: 45, elev: 25 });
plot ——通用多态切入点(包括表达字符串)
import { plot } from '@danielsimonjr/mathts-plot';
// numeric series → line
plot([0, 1, 4, 9]);
plot([0, 1, 2, 3], [0, 1, 4, 9]);
// expression string, sampled via functions/expression → line
plot('sin(x)', { from: 0, to: Math.PI, samples: 200 });
// two free variables → contour (default) or 3D surface
plot('x^2 + y^2', { from: -2, to: 2 });
plot('x^2 + y^2', { from: -2, to: 2, kind: 'surface' });
// array of Layer2D → overlay
plot([
{ type: 'line', x: [0, 1, 2], y: [0, 1, 2] },
{ type: 'scatter', x: [0, 1, 2], y: [0.1, 1.2, 1.8] },
]);
TikZ / LaTeX 输出
每个函数都接受 { format: 'tikz' } (默认为 'svg'),有一个
常规 toTikZ() 镜像 plot()。几何与 SVG 输出完全匹配(a)
sVG的左上下出自TikZ
\usepackage{tikz} 需要汇编结果.
import { toTikZ, line, surface } from '@danielsimonjr/mathts-plot';
// generic entry point, expression source → line
const tex = toTikZ('sin(x)', { from: 0, to: Math.PI });
// per-type function via the format option
const tex2 = line([0, 1, 2, 3], [0, 1, 4, 9], { format: 'tikz' });
// standalone: false → a bare tikzpicture for \input, not a compilable document
const z = [
[0, 1, 2],
[1, 2, 3],
[2, 3, 4],
];
const fragment = surface(z, { format: 'tikz', tikz: { standalone: false } });
toTikZ编号 :{ format: 'tikz' } 返回一个 LaTeX 字符串,而不是 SVG 。 与 standalone
(默认) true)字符串是一个完整的 \documentclass{...} 文档
(一) 编译; standalone: false 仅返回 tikzpicture 环境,指
被拉进来 \input{...} 从一个更大的文档.
它提供的东西
每个类型的标记函数 (x, y, opts?) => string 除非注明:
- 二维数字 :
line, (中文(简体) ),scatter, (中文(简体) ),bar, (中文(简体) ),area, (中文(简体) ),step, (中文(简体) ),errorbar(x, y, yerr, opts?), (中文(简体) ),quiver(x, y, u, v, opts?)。 。 。 . histogram(data, opts?)- 垃圾箱通过functions.histogram,然后使栏杆高度处于 宾馆中心.heatmap(z, opts?)维里迪斯有色网格,z作为z[row][col]。 。 。 .contour(z, opts?)- 游行广场在一个z[row][col]网络.overlay(layers, opts?)- 几个Layer2Ds在共享,自动缩放轴上.- 三维数字 :
surface(z, opts?)(线框或画家的算法填满),scatter3d(x, y, z, opts?), (中文(简体) ),curve3d(x, y, z, opts?)所有投射的正体图 相机( r)azim编号 :elev) (中文(简体) ). plot(...)− 数字系列、层数组和 表达式源字符串(通过@danielsimonjr/mathts-expression编号 :@danielsimonjr/mathts-functions) (中文(简体) ).viridis(t)—— 由 :heatmap编号 :contour编号 :surface, (中文(简体) ), 曝出再利用.
./render ——来自SVG的PNG/PDF(仅节点)
主要内容 . 条目只返回 SVG/TikZ 字符串。 对于文件输出, 导入孤立
节点子路径( 贝壳输出到 rsvg-convert 编号 : resvg 或者说 pdflatex 编号 : tectonic 路过:
import { renderToFile, latexToPdf } from '@danielsimonjr/mathts-plot/render';
await renderToFile(svgString, 'plot.png', { density: 144 });
见 docs/api/plot.md 页:1 RenderOptions, (中文(简体) ), PlotRenderError,以及 hasTool。 。 。 .
注释:
- 纯无害环境管理,
strictTypeScript, 除了 MathTS 基石之外没有运行时间依赖性 (单位:千美元)core编号 :functions编号 :expression在浏览器安全.输入. workbook通过此软件包制作其图表( 它以前的私人svg.ts绘图师是 (删除).
许可证
MIT (c) 小丹尼尔·西蒙.