mcpField
S
scientific-schematics

scientific-schematics

github.com/ovachiever创意与媒体56130 次安装48 周前更新
代码仓库

关于 scientific-schematics

scientific-schematics 是用于生成科学示意图和图表的技能,面向论文、海报及技术文档创作者。它可通过自然语言描述调用 Nano Banana Pro 生成图像,并迭代审查改进;也支持基于代码生成及编译 TikZ 图表。

主要功能

  1. 01自然语言描述生成科学图表
  2. 02通过迭代审查改进图像
  3. 03支持代码方式生成流程图、电路图和路径图
  4. 04编译 TikZ 文件为 PDF 或 PNG

适用场景

  1. 01制作神经网络架构图
  2. 02绘制生物通路或电路示意图
  3. 03生成研究方法流程图
  4. 04将 TikZ 图表编译为图像

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ovachiever/droid-tings --skill scientific-schematics

安装后在 Claude Code 中输入/scientific-schematics确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

example_usage.sh
IMPLEMENTATION_SUMMARY.md
QUICK_REFERENCE.md
README.md
test_ai_generation.py
references/
best_practices.md
scripts/
compile_tikz.py
generate_schematic_ai.py
generate_schematic.py

详细介绍

科学示意图与图表

概述

科学示意图与图表将复杂概念转化为清晰的视觉呈现,适用于出版物。此技能使用 Nano Banana Pro AI 生成所有图表。

工作原理:

  • 用自然语言描述图表
  • Nano Banana Pro 自动生成适合出版的高质量图像
  • 自动迭代优化(默认 3 轮)
  • 内置质量审查与改进
  • 几分钟内即可获得可供出版的成果
  • 无需编写代码、使用模板或手动绘制

**只需描述你想要的内容,Nano Banana Pro 就会为你生成。**所有图表都会保存在 figures/ 子文件夹中,并在论文/海报中引用。

快速入门:生成任意图表

只需描述图表,即可创建任意科学图表。Nano Banana Pro 会自动处理所有步骤:

# Generate any scientific diagram from a description
python scripts/generate_schematic.py "CONSORT participant flow diagram with 500 screened, 150 excluded, 350 randomized" -o figures/consort.png

# Neural network architecture
python scripts/generate_schematic.py "Transformer encoder-decoder architecture showing multi-head attention, feed-forward layers, and residual connections" -o figures/transformer.png

# Biological pathway
python scripts/generate_schematic.py "MAPK signaling pathway from EGFR to gene transcription" -o figures/mapk_pathway.png

# Custom iterations for complex diagrams
python scripts/generate_schematic.py "Complex circuit diagram with op-amp, resistors, and capacitors" -o figures/circuit.png --iterations 5

幕后流程:

  1. 生成 1:Nano Banana Pro 遵循科学图表的最佳实践,创建初始图像
  2. 审查 1:AI 评估图像的清晰度、标签、准确性和可访问性
  3. 生成 2:根据评审意见改进提示词并重新生成
  4. 审查 2:进行第二轮评估并提供具体反馈
  5. 生成 3:生成最终润色版本,解决所有评审意见

输出:三个版本(v1、v2、v3),以及包含质量评分和评审意见的详细审查日志。

配置

设置你的 OpenRouter API 密钥:

export OPENROUTER_API_KEY='your_api_key_here'

在此获取 API 密钥:https://openrouter.ai/keys

AI 生成最佳实践

科学图表的有效提示词:

✓ 优质提示词(具体、详细):

  • “展示参与者从筛查(n=500)到随机分组,再到最终分析流程的 CONSORT 流程图”
  • “Transformer 神经网络架构图:左侧为编码器堆叠,右侧为解码器堆叠,并展示多头注意力和交叉注意力连接”
  • “生物信号级联:EGFR 受体 → RAS → RAF → MEK → ERK → 细胞核,并标注磷酸化步骤”
  • “物联网系统框图:传感器 → 微控制器 → WiFi 模块 → 云服务 → 移动应用”

✗ 避免含糊的提示词:

  • “画一个流程图”(过于笼统)
  • “神经网络”(哪种类型?包含哪些组件?)
  • “通路图”(哪条通路?涉及哪些分子?)

应包含的关键要素:

  • 类型:流程图、架构图、通路图、电路图等
  • 组件:要包含的具体元素
  • 流程/方向:元素之间的连接方式(从左到右、从上到下)
  • 标签:要包含的关键注释或文本
  • 风格:任何具体的视觉要求

科学质量准则(自动应用):

  • 简洁的白色/浅色背景
  • 高对比度,易于阅读
  • 清晰易读的标签(至少 10pt)
  • 专业的排版(无衬线字体)
  • 色盲友好配色(Okabe-Ito 调色板)
  • 合理留白,避免拥挤
  • 适当添加比例尺、图例和坐标轴

经典代码生成

如需创建可复现、可进行版本控制且完全由程序控制的图表,请使用传统的代码生成方式。

何时使用此技能

遇到以下情况时,应使用此技能:

  • 创建神经网络架构图(Transformer、CNN、RNN 等)
  • 展示系统架构和数据流图
  • 绘制研究设计的方法流程图(CONSORT、PRISMA)
  • 可视化算法工作流和处理流水线
  • 创建电路图和电气示意图
  • 描绘生物通路和分子相互作用
  • 生成网络拓扑和层级结构
  • 展示概念框架和理论模型
  • 为技术论文设计框图

如何使用此技能

只需用自然语言描述你的图表。 Nano Banana Pro 会自动生成:

python scripts/generate_schematic.py "your diagram description" -o output.png

就是这么简单! AI 会处理:

  • ✓ 布局和构图
  • ✓ 标签和注释
  • ✓ 颜色和样式
  • ✓ 质量审核与优化
  • ✓ 可直接用于发表的输出

适用于所有图表类型:

  • 流程图(CONSORT、PRISMA 等)
  • 神经网络架构
  • 生物通路
  • 电路图
  • 系统架构
  • 框图
  • 任何科学可视化

无需编写代码、使用模板或手动画图。


AI 生成模式(Nano Banana Pro)

迭代优化工作流

AI 生成系统采用精细的三轮迭代优化流程:

第 1 轮:初始生成

提示词构建:

Scientific diagram guidelines + User request

内部提示词示例:

Create a high-quality scientific diagram with:
- Clean white background
- High contrast for readability
- Clear labels (minimum 10pt font)
- Professional typography
- Colorblind-friendly colors
- Proper spacing

USER REQUEST: CONSORT participant flow diagram showing screening, 
exclusion, randomization, and analysis phases with participant counts

输出: diagram_v1.png

第 2 轮:审核与改进

AI 质量审核:

  • 评估科学准确性
  • 检查标签是否清晰易读
  • 评估布局和构图
  • 验证无障碍性(灰度、色盲)
  • 评定质量分数(0-10)
  • 提供具体的改进建议

评审意见示例:

Score: 7/10

Strengths:
- Clear flow from top to bottom
- Good use of colors
- All phases labeled

Issues:
- Participant counts (n=X) are too small to read
- "Excluded" box overlaps with arrow
- Would benefit from reasons for exclusion

Suggestions:
- Increase font size for all numbers to at least 12pt
- Add more vertical spacing between boxes
- Include exclusion criteria in a separate annotation box

改进后的提示词:

[Original guidelines + user request]

ITERATION 2: Address these improvements:
- Increase font size for participant counts to 12pt minimum
- Add vertical spacing to prevent overlaps
- Include exclusion criteria in annotation box

输出: diagram_v2.png

第 3 轮:最终润色

第二次审核:

  • 验证改进是否已落实
  • 检查是否还存在问题
  • 进行最终质量评估

最终生成:

  • 纳入所有反馈
  • 生成可直接用于发表的图表

输出: diagram_v3.png(最终版本)

审核日志

所有迭代均会保存,并附带 JSON 审核日志:

{
  "user_prompt": "CONSORT participant flow diagram...",
  "iterations": [
    {
      "iteration": 1,
      "image_path": "figures/consort_v1.png",
      "score": 7.0,
      "critique": "..."
    },
    {
      "iteration": 2,
      "image_path": "figures/consort_v2.png",
      "score": 8.5,
      "critique": "..."
    },
    {
      "iteration": 3,
      "image_path": "figures/consort_v3.png",
      "score": 9.5,
      "critique": "..."
    }
  ],
  "final_score": 9.5
}

AI 生成高级用法

Python API
from scripts.generate_schematic_ai import ScientificSchematicGenerator

# Initialize generator
generator = ScientificSchematicGenerator(
    api_key="your_openrouter_key",
    verbose=True
)

# Generate with iterative refinement
results = generator.generate_iterative(
    user_prompt="Transformer architecture diagram",
    output_path="figures/transformer.png",
    iterations=3
)

# Access results
print(f"Final score: {results['final_score']}/10")
print(f"Final image: {results['final_image']}")

# Review individual iterations
for iteration in results['iterations']:
    print(f"Iteration {iteration['iteration']}: {iteration['score']}/10")
    print(f"Critique: {iteration['critique']}")
命令行选项
# Basic usage
python scripts/generate_schematic.py "diagram description" -o output.png

# Custom iterations (1-10)
python scripts/generate_schematic.py "complex diagram" -o diagram.png --iterations 5

# Verbose output (see all API calls and reviews)
python scripts/generate_schematic.py "flowchart" -o flow.png -v

# Provide API key via flag
python scripts/generate_schematic.py "diagram" -o out.png --api-key "sk-or-v1-..."
提示词工程技巧

1. 明确指定布局:

✓ "Flowchart with vertical flow, top to bottom"
✓ "Architecture diagram with encoder on left, decoder on right"
✓ "Circular pathway diagram with clockwise flow"

2. 添加定量细节:

✓ "Neural network with input layer (784 nodes), hidden layer (128 nodes), output (10 nodes)"
✓ "Flowchart showing n=500 screened, n=150 excluded, n=350 randomized"
✓ "Circuit with 1kΩ resistor, 10µF capacitor, 5V source"

3. 指定视觉风格:

✓ "Minimalist block diagram with clean lines"
✓ "Detailed biological pathway with protein structures"
✓ "Technical schematic with engineering notation"

4. 要求使用特定标签:

✓ "Label all arrows with activation/inhibition"
✓ "Include layer dimensions in each box"
✓ "Show time progression with timestamps"

5. 说明颜色要求:

✓ "Use colorblind-friendly colors"
✓ "Grayscale-compatible design"
✓ "Color-code by function: blue for input, green for processing, red for output"

AI 生成示例

示例 1:CONSORT 流程图
python scripts/generate_schematic.py \
  "CONSORT participant flow diagram for randomized controlled trial. \
   Start with 'Assessed for eligibility (n=500)' at top. \
   Show 'Excluded (n=150)' with reasons: age<18 (n=80), declined (n=50), other (n=20). \
   Then 'Randomized (n=350)' splits into two arms: \
   'Treatment group (n=175)' and 'Control group (n=175)'. \
   Each arm shows 'Lost to follow-up' (n=15 and n=10). \
   End with 'Analyzed' (n=160 and n=165). \
   Use blue boxes for process steps, orange for exclusion, green for final analysis." \
  -o figures/consort.png
示例 2:神经网络架构
python scripts/generate_schematic.py \
  "Transformer encoder-decoder architecture diagram. \
   Left side: Encoder stack with input embedding, positional encoding, \
   multi-head self-attention, add & norm, feed-forward, add & norm. \
   Right side: Decoder stack with output embedding, positional encoding, \
   masked self-attention, add & norm, cross-attention (receiving from encoder), \
   add & norm, feed-forward, add & norm, linear & softmax. \
   Show cross-attention connection from encoder to decoder with dashed line. \
   Use light blue for encoder, light red for decoder. \
   Label all components clearly." \
  -o figures/transformer.png --iterations 3
示例 3:生物通路
python scripts/generate_schematic.py \
  "MAPK signaling pathway diagram. \
   Start with EGFR receptor at cell membrane (top). \
   Arrow down to RAS (with GTP label). \
   Arrow to RAF kinase. \
   Arrow to MEK kinase. \
   Arrow to ERK kinase. \
   Final arrow to nucleus showing gene transcription. \
   Label each arrow with 'phosphorylation' or 'activation'. \
   Use rounded rectangles for proteins, different colors for each. \
   Include membrane boundary line at top." \
  -o figures/mapk_pathway.png
示例 4:系统架构
python scripts/generate_schematic.py \
  "IoT system architecture block diagram. \
   Bottom layer: Sensors (temperature, humidity, motion) in green boxes. \
   Middle layer: Microcontroller (ESP32) in blue box. \
   Connections to WiFi module (orange box) and Display (purple box). \
   Top layer: Cloud server (gray box) connected to mobile app (light blue box). \
   Show data flow arrows between all components. \
   Label connections with protocols: I2C, UART, WiFi, HTTPS." \
  -o figures/iot_architecture.png

其他工具

TikZ 编译(compile_tikz.py)

如果你有需要编译的现有 TikZ .tex 文件:

# Compile TikZ diagram to PDF
python scripts/compile_tikz.py diagram.tex -o diagram.pdf

# Compile and generate PNG
python scripts/compile_tikz.py diagram.tex --png --dpi 300

# Compile and preview
python scripts/compile_tikz.py diagram.tex --preview

如需了解 compile_tikz.py 的用法,请运行:

python scripts/compile_tikz.py --help

统一入口:generate_schematic.py

主入口同时支持 AI 生成和基于代码的生成:

# AI generation (default)
python scripts/generate_schematic.py "diagram description" -o output.png

# Explicit AI method
python scripts/generate_schematic.py "diagram description" -o output.png --method ai

# Code-based generation
python scripts/generate_schematic.py "1. Step one\n2. Step two" -o flow.tex --method code --type flowchart

# Custom iterations for AI
python scripts/generate_schematic.py "complex diagram" -o diagram.png --iterations 5

# Verbose mode
python scripts/generate_schematic.py "diagram" -o out.png -v

方法选择:

  • --method ai:使用 Nano Banana Pro 进行迭代优化(默认)
  • --method code:使用传统的基于代码的生成方式

基于代码的类型:

  • --type flowchart:生成 TikZ 流程图
  • --type circuit:生成电路图
  • --type pathway:生成生物通路

辅助脚本

compile_tikz.py

带质量检查的独立 TikZ 编译工具:

# Compile TikZ to PDF with verification
python scripts/compile_tikz.py flowchart.tex -o flowchart.pdf --verify

# Generate PNG with quality report
python scripts/compile_tikz.py flowchart.tex -o flowchart.pdf --png --dpi 300 --verify

# Preview with quality overlay
python scripts/compile_tikz.py flowchart.tex --preview --show-quality

注意: Nano Banana Pro AI 生成系统会在迭代优化过程中自动进行质量审核。每轮都会评估科学准确性、清晰度和无障碍性。

最佳实践概要

设计原则
  1. 清晰胜于复杂——简化图表,移除不必要的元素
  2. 样式保持一致——使用模板和样式文件
  3. 兼顾色盲人士的无障碍性——使用 Okabe-Ito 调色板和冗余编码
  4. 采用合适的字体——使用无衬线字体,字号至少为 7-8 pt
  5. 使用矢量格式——发表时始终使用 PDF/SVG
技术要求
  1. 分辨率——优先使用矢量格式;若使用光栅格式,则至少为 300 DPI
  2. 文件格式——LaTeX 使用 PDF,网页使用 SVG,PNG 作为备用格式
  3. 色彩空间——数字用途使用 RGB,印刷用途使用 CMYK(必要时进行转换)
  4. 线宽——至少为 0.5 pt,通常为 1-2 pt
  5. 文字大小——最终尺寸下至少为 7-8 pt
集成指南
  1. 在 LaTeX 中包含 - TikZ 使用 \input{},外部文件使用 \includegraphics{}
  2. 详尽添加图注 - 描述所有元素和缩写
  3. 在正文中引用 - 在叙述中解释图表
  4. 保持一致性 - 论文中的所有图表使用相同风格
  5. 版本控制 - 将源文件(.tex、.py)保存在仓库中

常见问题排查

TikZ 编译错误

问题:! Package tikz Error: I do not know the key '/tikz/...

  • 解决方案:缺少库——在导言区添加 \usetikzlibrary{...}

问题:文本或元素重叠

  • 解决方案:使用 AI 生成,它会自动处理间距
  • 解决方案:增加迭代次数:使用 --iterations 5 以改进细化效果
  • 解决方案:在路径生成器中使用 auto_spacing=True,自动调整间距

问题:箭头未正确连接

  • 解决方案:使用锚点:(node.east)、(node.north) 等
  • 解决方案:检查重叠报告,查看箭头与节点的交叉情况
Python 生成问题

问题:Schemdraw 元素未对齐

  • 解决方案:使用 .at() 方法精确定位
  • 解决方案:启用 auto_spacing 以避免重叠

问题:Matplotlib 文本渲染问题

  • 解决方案:设置 plt.rcParams['text.usetex'] = True 以使用 LaTeX 渲染
  • 解决方案:确保已安装 LaTeX

问题:导出质量差

  • 解决方案:AI 生成会自动生成高质量图像
  • 解决方案:对于 TikZ,使用:python scripts/compile_tikz.py diagram.tex --png --dpi 300

问题:生成后元素重叠

  • 解决方案:运行 detect_overlaps() 函数以识别问题区域
  • 解决方案:使用迭代细化:iterative_diagram_refinement(create_function)
  • 解决方案:将元素间距增加 20-30%
质量检查问题

问题:重叠检测误报

  • 解决方案:调整阈值:detect_overlaps(image_path, threshold=0.98)
  • 解决方案:在可视化报告中手动检查标记的区域

问题:生成的图像质量较低

  • 解决方案:AI 生成默认会生成高质量图像
  • 解决方案:增加迭代次数以获得更好的效果:使用 --iterations 5

问题:色盲模拟显示对比度较差

  • 解决方案:在代码中明确切换到 Okabe-Ito 调色板
  • 解决方案:添加冗余编码(形状、图案、线条样式)
  • 解决方案:增大颜色的饱和度和明度差异

问题:检测到高严重性重叠

  • 解决方案:查看 overlap_report.json,了解具体位置
  • 解决方案:增加这些特定区域的间距
  • 解决方案:使用调整后的参数重新运行,并再次验证

问题:可视化报告生成失败

  • 解决方案:检查 Pillow 和 matplotlib 是否已安装
  • 解决方案:确保图像文件可读取:Image.open(path).verify()
  • 解决方案:检查报告生成是否有足够的磁盘空间
无障碍问题

问题:灰度图中无法区分颜色

  • 解决方案:运行无障碍检查器:verify_accessibility(image_path)
  • 解决方案:添加图案、形状或线条样式作为冗余区分方式
  • 解决方案:提高相邻元素之间的对比度

问题:打印时文本太小

  • 解决方案:运行分辨率验证器:validate_resolution(image_path)
  • 解决方案:按照最终尺寸设计,使用至少 7-8 pt 的字体
  • 解决方案:在分辨率报告中检查实际尺寸

问题:无障碍检查持续失败

  • 解决方案:查看 accessibility_report.json,了解具体失败项
  • 解决方案:将颜色对比度至少提高 20%
  • 解决方案:定稿前使用实际的灰度转换进行测试

资源和参考资料

详细参考资料

如需了解特定主题的完整信息,请加载以下文件:

  • references/tikz_guide.md - 完整的 TikZ 语法、定位、样式和技巧
  • references/diagram_types.md - 科学图表类型目录及示例
  • references/best_practices.md - 出版标准和无障碍指南
  • references/python_libraries.md - Schemdraw、NetworkX 和 Matplotlib 图表库指南
外部资源

TikZ 和 LaTeX

Python 库

出版标准

与其他技能的集成

此技能可与以下技能协同使用:

  • Scientific Writing - 图表遵循图表最佳实践
  • Scientific Visualization - 共用调色板和样式
  • LaTeX Posters - 在海报图表中重用 TikZ 样式
  • Research Grants - 为提案绘制方法图
  • Peer Review - 评估图表的清晰度和无障碍性

快速参考清单

提交图表前,请确认:

视觉质量
  • 使用高质量图像格式(由 AI 生成的 PNG)
  • 无元素重叠(由 AI 自动处理)
  • 所有组件之间间距充足(由 AI 优化)
  • 对齐整洁、专业
  • 所有箭头均正确连接到目标位置
无障碍性
  • 使用色盲友好型调色板(Okabe-Ito)
  • 灰度模式下效果良好(已通过无障碍检查器测试)
  • 元素之间对比度充足(已验证)
  • 适当使用冗余编码(形状 + 颜色)
  • 通过所有色盲模拟检查
字体排印和可读性
  • 按最终尺寸计算,文字最小为 7-8 pt
  • 所有元素均已清晰、完整地标注
  • 字体系列和字号保持一致
  • 无文字重叠或裁切
  • 适用时注明单位
出版标准
  • 与稿件中的其他图表样式一致
  • 编写完整的图注,并定义所有缩写
  • 在稿件正文中恰当引用
  • 符合期刊对尺寸的具体要求
  • 导出为期刊要求的格式(PDF/EPS/TIFF)
质量验证(必需)
  • 运行 run_quality_checks() 并获得 PASS 状态
  • 检查重叠检测报告(无高严重性重叠)
  • 通过无障碍验证(灰度和色盲)
  • 按目标 DPI 验证分辨率(印刷需达到 300+)
  • 生成并检查视觉质量报告
  • 将所有质量报告与图表文件一同保存
文档和版本控制
  • 保存源文件(.tex、.py),以便日后修改
  • 将质量报告存档在 quality_reports/ 目录中
  • 记录配置参数(颜色、间距、尺寸)
  • Git 提交包含源文件、输出文件和质量报告
  • 在 README 或注释中说明如何重新生成图表
最终集成检查
  • 图表在编译后的稿件中显示正确
  • 交叉引用有效(\ref{} 指向正确的图表)
  • 图表编号与正文引用一致
  • 图注相对于图表出现在正确的页面
  • 无与图表相关的编译警告或错误

总结:AI 生成与基于代码的生成

快速决策指南

选择 AI 生成(Nano Banana Pro),如果:

  • ✓ 速度很重要(几分钟内获得结果)
  • ✓ 你希望自动进行质量审查和改进
  • ✓ 图表较复杂,包含许多视觉元素
  • ✓ 相较于编写代码,你更喜欢使用自然语言
  • ✓ 你需要立即获得可用于出版的图像
  • ✓ 你正在探索不同的设计方案

选择基于代码的生成,如果:

  • ✓ 你需要根据源代码精确复现
  • ✓ 你希望对图表源文件进行版本控制
  • ✓ 你要以编程方式生成许多相似的图表
  • ✓ 你需要原生 LaTeX TikZ 集成
  • ✓ 你希望对每个元素进行像素级精确控制
  • ✓ 图表由数据或算法生成
工作流对比
方面AI 生成基于代码
获得首个结果所需时间2-3 分钟15-30 分钟
迭代自动(3 轮)手动
质量审查AI 自动完成手动或通过脚本完成
自定义自然语言完全的编程控制
可复现性基于提示词基于代码(精确)
学习曲线低(只需描述)中到高(需要学习库)
输出格式PNG/JPGPDF/SVG/EPS/PNG
版本控制提示词 + 图像源代码 + 输出
最适合快速迭代、复杂视觉内容可复现研究、数据驱动
混合方案(推荐)

许多用户发现,采用混合工作流效果很好:

  1. 使用 AI 制作原型:通过自然语言快速生成初始设计
  2. 审查并改进:利用 AI 的迭代改进功能,使设计接近最终效果
  3. 用代码重建(可选):如果需要精确复现,可将获批的设计用代码重建
  4. 版本控制:同时保留 AI 提示词和代码版本
环境设置

AI 生成:

# Required
export OPENROUTER_API_KEY='your_api_key_here'

# Get key at: https://openrouter.ai/keys

基于代码的生成:

# Install Graphviz
brew install graphviz  # macOS
sudo apt-get install graphviz  # Linux

# Install Python packages
pip install graphviz schemdraw networkx matplotlib
入门指南

最简单的用法(AI):

python scripts/generate_schematic.py "your diagram description" -o output.png

最简单的用法(代码):

python scripts/generate_schematic.py "1. Step one\n2. Step two" -o flow.tex --method code

使用此技能创建清晰、易于理解且达到出版质量的图表,有效传达复杂的科学概念。AI 驱动的工作流通过迭代改进确保图表达到专业标准,而基于代码的方案则为研究出版物提供精确的可复现性。

评论

支持 Markdown