| name | lightest-data-viz |
| skill_id | lightest_data_viz_skill |
| controlled | true |
| description | 当用户要用 CSV/Excel 真实数据画研报 Exhibit、科学 figure(折线/柱状/热力图等)并嵌入 Typst/Word/Excel 时使用;走 matplotlib/seaborn 出图,禁止编造图内数字。**触发**:CSV 画图、Excel 可视化、Exhibit、matplotlib、seaborn、研报配图、科学 figure。**加载**:`skills_fetch(skill_ids=["lightest_data_viz_skill"])` → read `data-viz-router-and-workflow.md` → `python-matplotlib-seaborn.md` → `report-chart-embed.md`。**勿用**:纯 EDA/统计报告无配图 → 开源 optional `lightest_data_analysis_skill`(lightest-skills `optional/lightest-data-analysis`);聊天里看个趋势 → `chart_visualization_skill`;Fletcher 架构图 → `lightest_typst_report_skill`;Excel 原生图表 → `lightest_xlsx_skill`。 |
| references | ["references/data-viz-router-and-workflow.md","references/python-matplotlib-seaborn.md","references/report-chart-embed.md"] |
LighTest 数据可视化
从真实数据到可嵌入的静态图(PNG/PDF/SVG)。对话内快速示意走 chart_visualization_skill 的 ```graph```;精确数字、研报 Exhibit、论文 figure 走本 skill。
路由(先读再动手)
| 用户要什么 | 走哪条 | 不要误用 |
|---|
项目里 *.csv / xlsx → 正式图进 Typst/Word/PDF | 本 skill Phase 0–4 | ```graph``` 冒充 Exhibit |
| 只要三线表、不要图 | lightest_xlsx / Typst #table | 强行 matplotlib |
| 聊天里定性趋势、无精确刻度 | chart_visualization_skill | 本 skill 填 y 值 |
| 架构 / 流程 / ≥3 节点有向图 | lightest_typst_report → Fletcher | matplotlib 流程图 |
| Excel 里可改 series 的原生 chart | lightest_xlsx_skill | 仅 PNG 预览当终稿 |
| 纯 EDA、检验、Findings 无配图 | lightest_data_analysis_skill(optional) | 本 skill 深读 |
| 图注、Exhibit 叙述、去 AI 味 prose | lightest_writing_skill | 不产图文件 |
Typst #figure、compile、CeTZ 小数据 | lightest_typst_report_skill | 大数据仍 Python 预渲染 |
60 秒自检:要图还是表?数字是否已 read?交付容器是 chat / figures/ / Typst / Word / xlsx?体裁是 Exhibit 还是 Figure?
阅读顺序:data-viz-router-and-workflow.md(决策树 + Phase 0–4)→ 按栈读 python-matplotlib-seaborn.md 或 report-chart-embed.md。
技能分工(简表)
| 技能 | 何时 |
|---|
| 本技能 | CSV/Excel→Python 出图、Exhibit/Figure 嵌入、配色与导出 |
lightest_data_analysis_skill | EDA、检验(开源 optional,非 App 内置) |
chart_visualization_skill | 对话内 ```graph``` / Mermaid |
lightest_xlsx_skill | 数据源、透视、Excel 内原生 chart |
lightest_docx_skill | Word 原生 chart 或 matplotlib PNG |
lightest_typst_report_skill | #figure + compile;CeTZ-Plot 小数据 |
lightest_writing_skill | caption prose;不编造图内数字 |
强制流程
- 路由 —
data-viz-router-and-workflow.md §2 决策树(Python / CeTZ / openpyxl / graph)
- 生成 —
python-matplotlib-seaborn.md;项目 scripts/plot_<id>.py,输出 <project>/data/figures/
- 嵌入 —
report-chart-embed.md(Typst / docx / xlsx + 验收)
- 样式 — 复制或引用
scripts/chart_style.py(apply_publication_style / save_publication_figure)
端到端示例:sales.csv → read → matplotlib → Typst
用户:「用项目里的 data/sales.csv 画季度营收折线,放进 Typst 报告。」
Phase 0 确认路径、列名、单位;read(data/sales.csv) — 无文件/空表则 §错误处理
Phase 1 折线(时间 × 数值);preset sell_side 或 nature
Phase 2 scripts/plot_sales.py → terminal: python scripts/plot_sales.py
→ 断言 data/figures/sales_trend.png (+ .pdf)
Phase 3 report.typ:
#figure(image("figures/sales_trend.png", width: 88%),
caption:[...],) <fig:sales-trend>
正文 @fig:sales-trend
Phase 4 gate:图极值与 read 行一致 → lightest_typst_report writing_compile_check
最小脚本骨架(细节见 reference §8.3):
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
from chart_style import apply_publication_style, save_publication_figure
ROOT = Path(__file__).resolve().parents[1]
df = pd.read_csv(ROOT / "data" / "sales.csv", parse_dates=["date"])
apply_publication_style("sell_side")
fig, ax = plt.subplots(figsize=(6.5, 4))
ax.plot(df["date"], df["revenue"])
save_publication_figure(fig, ROOT / "data" / "figures" / "sales_trend", formats=("png", "pdf"))
Typst 片段:#figure(image("figures/sales_trend.png"), caption:[...]) <fig:sales-trend>;完整目录与双 Y 轴变体见 report-chart-embed.md §7。
协作链:read CSV → 本 skill 出图 → lightest_typst_report_skill 编译 → lightest_writing_skill 润色 caption(数字仍以 CSV/gate 为准)。
数据 gate(强制)
- 图内数字 仅来自
read 过的 CSV/Excel/工具结果;无来源 → 停止出图,向用户索要或标 [pending]
- 禁止「典型行业」虚构曲线进正式 Exhibit;示意须标 illustrative 且不进正式编号
- 生成后:脚本打印
df.head() / 关键极值;Agent 再 read CSV 抽样交叉核对
- 改图后:caption 与正文引用数字须与 gate 日志一致;writing 不得断言图中不存在的细分项
错误处理
| 场景 | 动作 | 禁止 |
|---|
文件不存在(read / FileNotFoundError) | 报路径;请用户确认或放入 data/;不建假 CSV | 用 graph 画假趋势 |
| 空 CSV(0 行或仅表头) | Phase 0 停止;说明空表;索要有效数据或 sheet 名 | read_csv 后静默空图 |
| 缺列 / 列名不符 | 列出 read 所见列名;请用户映射 date/revenue 等 | 猜列填数 |
| 全 NaN 关键列 | 同空表;建议清洗或换 sheet | 用 0 填坑 |
| ModuleNotFoundError | 提示 pip install matplotlib pandas seaborn(项目 venv) | 降级为编造数据的 graph |
| 中文乱码 | apply_publication_style CJK 字体;CSV UTF-8 | 忽略标签方块 |
| Typst image not found | 先跑 plot;检查 figures/ 相对 report.typ | 改 caption 数字凑图 |
失败时交付:[Figure pending: 需 <path> 有效销量数据] + 已确认的列结构,不交付带数字的正式图。
输出形态速查(§2 摘要)
| 形态 | 何时 |
|---|
| matplotlib/seaborn | 默认:CSV→PNG/PDF,data/figures/ |
| CeTZ-Plot | Typst 同编译、点数少(见 typst visualization-guide) |
```graph``` | 无精确数据、流程示意 |
| openpyxl chart | 用户要 Excel 内可改图 |
| Word 原生 / PNG | 卖方 Word:lightest_docx |
依赖
pip install matplotlib pandas seaborn
python -c "import matplotlib, pandas, seaborn; print('ok')"
终端 cwd = 项目根;脚本与 figures/ 写在用户项目,不修改 skill 包(可只读 import chart_style)。
任务速查
| 用户说 | 读什么 |
|---|
| CSV/Excel 画图、matplotlib | router → python-matplotlib-seaborn |
| 嵌入 Typst / Word / Exhibit | router → report-chart-embed |
| 只在聊天里看个趋势 | chart_visualization_skill |
| Excel 里做可编辑 chart | lightest_xlsx_skill |
| 架构/流程图 | lightest_typst_report → visualization-guide |
验收(交付前)
详细 checklist:report-chart-embed.md §8;路由与 Phase 表:data-viz-router-and-workflow.md。