# @danielsimonjr/mathts-plot 中文文档

规范地址：https://npmcn.com/package/%40danielsimonjr/mathts-plot/

版本：0\.4\.31
npm 元数据更新时间：2026-11-11T10:02:47.587Z
中文译文更新时间：2026-11-11T10:49:58.389Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40danielsimonjr/mathts-plot
原文对照：https://npmcn.com/package/%40danielsimonjr/mathts-plot/?lang=original
项目主页：https://github.com/danielsimonjr/MathTS#readme
源码仓库：https://github.com/danielsimonjr/MathTS

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：74.4 kB，46 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2026-07-09T11:40:36.401Z
- 最新版本发布：2026-11-11T10:02:46.978Z
- 近 30 天下载量：3436（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：82（近 12 个月 82 个）

## 中文简介

无头 SVG 2D/3D 为 MathTS 绘制图——依赖光,表达意识,以核心/功能/表达为基础

## 安装

```sh
npm install @danielsimonjr/mathts-plot
```

也可以使用：`pnpm add @danielsimonjr/mathts-plot`、`yarn add @danielsimonjr/mathts-plot`、`bun add @danielsimonjr/mathts-plot`

## README

# @danielsimonjr/ mathts-plot 页面存档备份,存于互联网档案馆

无头 SVG 2D/3D 绘图 [数学](https://github.com/danielsimonjr/mathts)。 。 。 .

纯函数返回自成一体的 SVG 字符串——没有浏览器,没有画布,没有运行时间 数学和科学基础以外的依赖性(`core`编号 :`functions`编号 :`expression`) (中文(简体) ). 每个函数 强迫其输入, 绝不投出错误数据: 空, `NaN`,或 `Infinity` 输入为 a "没有数据"的占位符 SVG 而不是崩溃. 见 `docs/superpowers/specs/2026-07-07-plotting-design.md` 为设计.

## 安装

```sh
npm install @danielsimonjr/mathts-plot
```

## 使用量

下方的每个函数返回自成一体的 SVG 字符串(`<svg ...>...</svg>`)——使它成为 直接在一个 `<img src="data:image/svg+xml,...">`写给 `.svg` 文件,或丢弃它 输入 HTML.

### `line` - 一个系列,或与其它系列重叠

```ts
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` ——在共享的自动缩放轴上结合多层

```ts
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 表面通过正图投影 + 画家算法

```ts
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` ——通用多态切入点(包括表达字符串)

```ts
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}` 需要汇编结果.

```ts
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?)`** - 几个 `Layer2D`s在共享,自动缩放轴上.
-   **三维**数字 : `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` 路过:

```ts
import { renderToFile, latexToPdf } from '@danielsimonjr/mathts-plot/render';

await renderToFile(svgString, 'plot.png', { density: 144 });
```

见 `docs/api/plot.md` 页:1 `RenderOptions`, (中文(简体) ), `PlotRenderError`,以及 `hasTool`。 。 。 .

注释:

-   纯无害环境管理, `strict` TypeScript, 除了 MathTS 基石之外没有运行时间依赖性 (单位:千美元)`core`编号 :`functions`编号 :`expression`在浏览器安全 `.` 输入.
-   `workbook` 通过此软件包制作其图表( 它以前的私人 `svg.ts` 绘图师是 (删除).

## 许可证

MIT (c) 小丹尼尔·西蒙.

## 常见问题

### @danielsimonjr/mathts-plot 是什么？

无头 SVG 2D/3D 为 MathTS 绘制图——依赖光,表达意识,以核心/功能/表达为基础

### 如何安装 @danielsimonjr/mathts-plot？

在项目目录运行 npm install @danielsimonjr/mathts-plot，或使用 pnpm add / yarn add / bun add。

### @danielsimonjr/mathts-plot 支持 TypeScript 吗？

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

### @danielsimonjr/mathts-plot 支持 ESM 还是 CommonJS？

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

### @danielsimonjr/mathts-plot 可以商用吗？

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

### @danielsimonjr/mathts-plot 的下载量有多少？

根据 npm 官方下载统计，@danielsimonjr/mathts-plot 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,436 次，日均约 115 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @danielsimonjr/mathts-plot 还在维护吗？

最新版本 0\.4\.31 发布于 2026/11/11（今天）；至今共发布 82 个版本，其中过去 12 个月发布了 82 个；首次发布于 2026/07/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

