scientific-visualization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scientific Visualization

科学可视化

Build figures that preserve scientific meaning before optimizing appearance. Separate universal principles from dated publisher rules, preserve raw data and transformations, use color redundantly, and inspect delivered files rather than trusting plotting defaults.
在优化外观之前,先构建能够保留科学含义的图表。应区分通用原则与具有时效性的出版商规则,保留原始数据及其转换,以冗余方式使用颜色,并检查交付文件,而不是依赖绘图库的默认设置。

Non-negotiable guardrails

不可违背的守则

  • Never alter, hide, invent, or selectively enhance data to improve a figure.
  • Preserve raw tables/images, exclusions, missing-value codes, analysis code, normalization, binning, image adjustments, and random seeds.
  • Do not infer journal requirements. Identify the exact journal, article type, figure type, and submission phase; verify its live official guidance.
  • Do not claim that a palette, DPI value, format, or automated report makes a figure accessible or journal-compliant.
  • Do not silently connect missing observations, suppress inconvenient points, upsample images as if detail increased, or tune axes/dual axes to exaggerate a conclusion.
  • Keep interactive and static outputs as distinct deliverables. Interactive hover is not a substitute for labels, alt text, keyboard access, an accessible data table, or a static fallback.
Read
references/publication_guidelines.md
for deceptive-encoding and integrity checks. Read
references/journal_requirements.md
only after the target and phase are known.
  • 绝不要为了改善图表而修改、隐藏、编造或选择性增强数据。
  • 保留原始表格/图像、排除项、缺失值编码、分析代码、归一化、分箱、图像调整和随机种子。
  • 不要推测期刊要求。确定具体的期刊、文章类型、图表类型和投稿阶段;核实其最新的官方指南。
  • 不要声称某种调色板、DPI 值、格式或自动报告能够使图表具备无障碍性或符合期刊要求。
  • 不要在未说明的情况下连接缺失观测值、隐藏不便呈现的点、以仿佛细节有所增加的方式对图像升采样,或调整坐标轴/双坐标轴以夸大结论。
  • 将交互式输出和静态输出作为不同交付物。交互式悬停提示不能替代标签、替代文本、键盘访问、无障碍数据表或静态回退版本。
阅读
references/publication_guidelines.md
以了解欺骗性编码和完整性检查。只有在确定目标期刊和投稿阶段后,才阅读
references/journal_requirements.md
。

Workflow

工作流程

1. Define the evidence and destination

1. 定义证据与交付目标

Record:
  • audience and medium: manuscript, web, slide, poster, supplement;
  • exact publisher/journal, article type, submission phase, and intended final width;
  • variable semantics, units, sample/replicate structure, missing/censored values;
  • estimator and uncertainty definition;
  • transformations: filtering, aggregation, normalization, smoothing, bins, image processing;
  • source-data paths/identifiers and output provenance.
If requirements are not known, create a provisional general figure and label all publisher choices as pending verification.
记录:
  • 受众和媒介:稿件、Web、幻灯片、海报、补充材料;
  • 具体出版商/期刊、文章类型、投稿阶段和预期最终宽度;
  • 变量语义、单位、样本/重复结构、缺失/删失值;
  • 估计量和不确定性的定义;
  • 转换:筛选、聚合、归一化、平滑、分箱、图像处理;
  • 源数据路径/标识符和输出溯源信息。
如果尚不清楚要求,则创建一个临时的通用图表,并将所有出版商相关选项标记为待核实。

2. Choose an honest encoding

2. 选择诚实的编码方式

Prefer position on a common scale. Before coding, check:
  • Bars/areas: normally include zero because length/area is measured from a baseline.
  • Points/lines: nonzero limits can be valid; show context and disclose breaks.
  • Uncertainty: name SD, SE, CI, percentile, posterior, or another interval; state
    n
    and the unit of replication.
  • Raw observations: show them when feasible; do not let jitter obscure categories/values.
  • Missing data: distinguish missing, zero, censored, and excluded; use gaps or explicit model/interpolation styling.
  • Area/volume: scale area/volume, not radius/diameter; avoid decorative 3D.
  • Log axes: label the base/transform and declare how zero/negative values are handled.
  • Binning/smoothing: record edges, bandwidth/window, method, and sensitivity.
  • Normalization: state formula/reference and keep limits consistent across compared panels.
  • Dual axes: prefer aligned panels; if unavoidable, justify units and do not engineer apparent correlation.
  • Images: preserve originals, disclose whole-image adjustments, show scale bars, and avoid clipped/erased background.
优先采用共同尺度上的位置。编码前检查:
  • 柱状图/面积: 通常应包含零,因为长度/面积是从基线开始度量的。
  • 点/线: 非零坐标轴范围可以是合理的;应提供上下文并说明断轴。
  • 不确定性: 指明是 SD、SE、CI、百分位区间、后验分布,还是其他区间;注明
    n
    和重复单位。
  • 原始观测值: 在可行时展示;不要让 jitter 掩盖类别/数值。
  • 缺失数据: 区分缺失、零、删失和排除;使用间断或明确的模型/插值样式。
  • 面积/体积: 按面积/体积缩放,而不是半径/直径;避免装饰性的 3D。
  • 对数坐标轴: 标明底数/变换,并说明如何处理零值/负值。
  • 分箱/平滑: 记录分箱边界、带宽/窗口、方法及敏感性。
  • 归一化: 说明公式/参考基准,并在相互比较的面板间保持范围一致。
  • 双坐标轴: 优先使用对齐面板;如果不可避免,应说明单位,且不要人为营造表面相关性。
  • 图像: 保留原图,披露整幅图像的调整,显示比例尺,并避免裁剪/擦除背景。

3. Design accessibility in, not after

3. 从一开始就融入无障碍设计

  • Use color plus marker, line style, hatching, direct label, or panel separation.
  • Choose qualitative, sequential, diverging, or cyclic color according to data semantics.
  • Audit foreground/background contrast at the rendered size.
  • Make missing and out-of-range values explicit.
  • Provide alt text, a longer description for complex figures, and underlying data for web delivery.
  • Treat WCAG 2.2 as web guidance: 4.5:1 normal text, 3:1 large text, and 3:1 for graphical objects required for understanding; color cannot be the only cue. Applicability and exceptions matter.
See
references/color_palettes.md
. A grayscale screen is useful but is not a complete color-vision or accessibility test.
  • 将颜色与 marker、line style、hatching、直接标签或面板分隔等冗余编码结合使用。
  • 依据数据语义选择定性、顺序、发散或循环配色。
  • 在实际渲染尺寸下审查前景/背景对比度。
  • 明确标示缺失值和超范围值。
  • 为 Web 交付提供替代文本、复杂图表的详细描述和底层数据。
  • 将 WCAG 2.2 视为 Web 指南:普通文本 4.5:1,大文本 3:1,理解图形所需图形对象 3:1;颜色不能是唯一提示。其适用范围和例外情况很重要。
参阅
references/color_palettes.md
。灰度屏幕检查很有用,但不能替代完整的色觉或无障碍测试。

4. Implement with scoped styles

4. 使用限定范围的样式实现

Use Matplotlib's object-oriented API and temporary style contexts:
python
import matplotlib.pyplot as plt

from style_presets import style_context

with style_context("default", palette_name="okabe_ito_on_white"):
    fig, ax = plt.subplots(
        figsize=(89 / 25.4, 60 / 25.4),
        layout="constrained",
    )
    ax.plot(x, y, marker="o", label="Observed")
    ax.set(xlabel="Time (hours)", ylabel="Response (unit)")
    ax.legend()
layout="constrained"
supports colorbars, nested GridSpec, subfigures, and
subplot_mosaic
. Do not call
tight_layout()
afterward; it disables constrained layout.
For exact physical dimensions, do not use
bbox_inches="tight"
unless the changed page size is intentional.
使用 Matplotlib 的面向对象 API 和临时样式上下文:
python
import matplotlib.pyplot as plt

from style_presets import style_context

with style_context("default", palette_name="okabe_ito_on_white"):
    fig, ax = plt.subplots(
        figsize=(89 / 25.4, 60 / 25.4),
        layout="constrained",
    )
    ax.plot(x, y, marker="o", label="Observed")
    ax.set(xlabel="Time (hours)", ylabel="Response (unit)")
    ax.legend()
layout="constrained"
支持 colorbar、嵌套 GridSpec、subfigures 和
subplot_mosaic
。之后不要调用
tight_layout()
;调用它会禁用 constrained layout。
如需精确的物理尺寸,不要使用
bbox_inches="tight"
,除非页面尺寸的变化是有意为之。

Color normalization

颜色标准化

python
import matplotlib as mpl

norm = mpl.colors.TwoSlopeNorm(vmin=-2, vcenter=0, vmax=5)
cmap = mpl.colormaps["RdBu_r"].with_extremes(bad="#777777")
image = ax.imshow(values, norm=norm, cmap=cmap, interpolation="nearest")
fig.colorbar(image, ax=ax, label="Change (unit)")
Use
LogNorm
,
CenteredNorm
,
SymLogNorm
,
BoundaryNorm
, or
TwoSlopeNorm
only when its mapping matches the scientific meaning.
python
import matplotlib as mpl

norm = mpl.colors.TwoSlopeNorm(vmin=-2, vcenter=0, vmax=5)
cmap = mpl.colormaps["RdBu_r"].with_extremes(bad="#777777")
image = ax.imshow(values, norm=norm, cmap=cmap, interpolation="nearest")
fig.colorbar(image, ax=ax, label="Change (unit)")
仅在映射符合科学含义时,才使用
LogNorm
、
CenteredNorm
、
SymLogNorm
、
BoundaryNorm
或
TwoSlopeNorm
。

Seaborn

Seaborn

Seaborn 0.13.2 uses the current
errorbar
API:
python
sns.lineplot(
    data=frame,
    x="time",
    y="response",
    hue="treatment",
    style="treatment",
    markers=True,
    errorbar=("ci", 95),
    n_boot=5000,
    seed=20260723,
    ax=ax,
)
Axes-level functions fit custom Matplotlib layouts; figure-level functions create their own figures/facets. Do not customize Seaborn's internal artist lists as if they were stable API.
Seaborn 0.13.2 使用当前的
errorbar
API:
python
sns.lineplot(
    data=frame,
    x="time",
    y="response",
    hue="treatment",
    style="treatment",
    markers=True,
    errorbar=("ci", 95),
    n_boot=5000,
    seed=20260723,
    ax=ax,
)
Axes-level 函数适合自定义 Matplotlib 布局;figure-level 函数会自行创建图形或分面。不要将自定义 Seaborn 内部 artist 列表当作稳定 API。

Plotly

Plotly

  • Use
    write_html()
    for interaction and
    write_image()
    /
    plotly.io.write_images()
    for static output.
  • Kaleido 1.3.0 requires Chrome/Chromium; it no longer bundles Chrome.
  • Current static formats: PNG, JPEG, WebP, SVG, PDF. EPS is Kaleido v0-only.
  • Do not pass deprecated
    engine=
    or use Orca/
    plotly.io.kaleido.scope
    .
  • width
    ,
    height
    , and
    scale
    control pixels;
    scale=3
    is not inherently “300 DPI.”
  • WebGL traces embed raster content in PDF/SVG.
  • Fully offline exports need local external assets when a figure references MathJax/topojson/tiles.
  • 使用
    write_html()
    输出交互式内容,使用
    write_image()
    /
    plotly.io.write_images()
    输出静态内容。
  • Kaleido 1.3.0 需要 Chrome/Chromium;它不再捆绑 Chrome。
  • 当前支持的静态格式:PNG、JPEG、WebP、SVG、PDF。EPS 仅受 Kaleido v0 支持。
  • 不要传入已弃用的
    engine=
    ,也不要使用 Orca/
    plotly.io.kaleido.scope
    。
  • width
    、
    height
    和
    scale
    控制像素;
    scale=3
    并不等同于“300 DPI”。
  • WebGL trace 会在 PDF/SVG 中嵌入栅格内容。
  • 完全离线导出时,如果图表引用 MathJax/topojson/tiles,需要使用本地外部资源。

5. Export explicitly and record provenance

5. 明确导出并记录溯源信息

python
from figure_export import export_figure

report = export_figure(
    fig,
    "outputs/figure1",
    formats=["pdf", "png"],
    dpi=600,
    bbox_inches=None,  # preserve figure page dimensions
    provenance={
        "raw_data": "data/source.csv",
        "transformations": ["predeclared QC filter", "group mean"],
        "uncertainty": "95% bootstrap CI; seed 20260723",
        "missing_data": "retained as gaps",
    },
    write_manifest=True,
)
The exporter refuses implicit overwrite, writes atomically, keeps vector DPI for embedded rasters, uses TIFF LZW, and can use PDF/PS Type 42 fonts. It does not validate scientific content or publisher acceptance.
For editable fonts:
  • PDF/PS Type 42 embeds TrueType fonts.
  • svg.fonttype="none"
    keeps text editable/searchable but does not embed fonts; appearance depends on installed fonts.
  • svg.fonttype="path"
    preserves glyph appearance as paths but loses editable/searchable text.
Use an opaque explicit background unless transparency is required; blending against another background changes apparent contrast.
python
from figure_export import export_figure

report = export_figure(
    fig,
    "outputs/figure1",
    formats=["pdf", "png"],
    dpi=600,
    bbox_inches=None,  # preserve figure page dimensions
    provenance={
        "raw_data": "data/source.csv",
        "transformations": ["predeclared QC filter", "group mean"],
        "uncertainty": "95% bootstrap CI; seed 20260723",
        "missing_data": "retained as gaps",
    },
    write_manifest=True,
)
导出器会拒绝未经明确授权的覆盖,以原子方式写入,在嵌入栅格图像时保留矢量 DPI,使用 TIFF LZW,并可使用 PDF/PS Type 42 字体。它不会验证科学内容或出版商是否接受。
对于可编辑字体:
  • PDF/PS Type 42 会嵌入 TrueType 字体。
  • svg.fonttype="none"
    会使文本保持可编辑和可搜索,但不会嵌入字体;显示效果取决于已安装的字体。
  • svg.fonttype="path"
    会以路径形式保留字形外观,但会失去可编辑和可搜索的文本。
除非确需透明度,否则使用明确的不透明背景;与其他背景混合会改变实际显现的对比度。

6. Inspect, compare, and review

6. 检查、比较和审核

  1. Inspect file metadata.
  2. Audit palette contrast/grayscale separation.
  3. Compare against a dated publisher snapshot.
  4. View at final size in the manuscript/web context.
  5. Manually review fonts, embedded rasters, clipping, legends, scale bars, image integrity, caption, alt text, and source data.
  6. Re-check the live target-journal page immediately before upload.
  1. 检查文件元数据。
  2. 审核调色板对比度和灰度区分效果。
  3. 与带日期的出版商快照进行比较。
  4. 在稿件/Web 场景中以最终尺寸查看。
  5. 手动审核字体、嵌入的栅格图像、裁剪情况、图例、比例尺、图像完整性、图注、替代文本和源数据。
  6. 在上传前立即重新核查目标期刊的实时页面。

Pinned snapshot

固定版本快照

The examples and smoke tests use direct package pins current on 2026-07-23:
bash
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  --with "seaborn==0.13.2" \
  --with "plotly==6.9.0" \
  --with "kaleido==1.3.0" \
  --with "pillow==12.3.0" \
  --with "pypdf==6.14.2" \
  python your_figure.py
This is a dated direct-dependency snapshot, not a transitive lock. Use the project's uv lock for exact replay; this skill intentionally ships no dependency lock.
示例和冒烟测试使用当前截至 2026-07-23 的直接依赖固定版本:
bash
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  --with "seaborn==0.13.2" \
  --with "plotly==6.9.0" \
  --with "kaleido==1.3.0" \
  --with "pillow==12.3.0" \
  --with "pypdf==6.14.2" \
  python your_figure.py
这是带日期的直接依赖快照,而不是传递依赖锁定文件。使用项目的 uv lock 实现精确复现;此 skill 有意不附带依赖锁文件。

Bundled CLIs

内置 CLI

All helpers are deterministic, network-free, bounded, reject symlink inputs/destinations where relevant, and refuse overwrite unless
--force
is explicit.
所有辅助工具均为确定性、无需联网且运行范围受限;在相关场景下会拒绝符号链接输入/目标;除非明确指定
--force
,否则拒绝覆盖。

Inspect raster/vector metadata

检查栅格/矢量元数据

bash
uv run --isolated --no-project --python 3.13 \
  --with "pillow==12.3.0" \
  python scripts/image_metadata.py figure.tiff \
  --format tiff --mode RGB --min-dpi 300 --target-width-mm 85 \
  --alpha-policy forbid
Supports raster images (Pillow), SVG, PDF (pypdf), and EPS/PS. Reports dimensions, DPI/effective DPI, mode, alpha, ICC presence, compression, page size, and conservative first-page PDF font resources. It does not inspect every embedded raster in a vector container.
bash
uv run --isolated --no-project --python 3.13 \
  --with "pillow==12.3.0" \
  python scripts/image_metadata.py figure.tiff \
  --format tiff --mode RGB --min-dpi 300 --target-width-mm 85 \
  --alpha-policy forbid
支持栅格图像(Pillow)、SVG、PDF(pypdf)以及 EPS/PS。报告尺寸、DPI/有效 DPI、模式、alpha、ICC 是否存在、压缩方式、页面大小,并以保守方式检查 PDF 首页字体资源。它不会检查矢量容器中每个嵌入的栅格图像。

Audit palette contrast and grayscale

审核调色板对比度与灰度效果

bash
uv run --isolated --no-project --python 3.13 \
  python scripts/palette_audit.py \
  --palette okabe_ito_on_white \
  --background FFFFFF \
  --role graphical
Reports exact WCAG sRGB contrast plus pairwise CIE L* grayscale screening. The grayscale threshold is a heuristic, not a standard.
bash
uv run --isolated --no-project --python 3.13 \
  python scripts/palette_audit.py \
  --palette okabe_ito_on_white \
  --background FFFFFF \
  --role graphical
报告精确的 WCAG sRGB 对比度,以及成对 CIE L* 灰度筛查结果。灰度阈值是启发式规则,不是标准。

Plan/screen publisher export

规划/筛查出版商导出

bash
uv run --isolated --no-project --python 3.13 \
  python scripts/export_plan.py \
  --publisher nature \
  --figure-type combination \
  --width single \
  --phase final
Add
--input figure.pdf
to screen machine-readable properties. Profiles are official-source snapshots accessed 2026-07-23, not automatic compliance rules.
bash
uv run --isolated --no-project --python 3.13 \
  python scripts/export_plan.py \
  --publisher nature \
  --figure-type combination \
  --width single \
  --phase final
添加
--input figure.pdf
可以筛查机器可读属性。配置文件是访问于 2026-07-23 的官方来源快照,并非自动合规规则。

Preview styles

预览样式

bash
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  python scripts/style_preview.py \
  --output outputs/style-preview \
  --style default \
  --palette okabe_ito_on_white \
  --formats png,svg
bash
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  python scripts/style_preview.py \
  --output outputs/style-preview \
  --style default \
  --palette okabe_ito_on_white \
  --formats png,svg

Inspect/write styles and smoke-test export

检查/写入样式并执行导出冒烟测试

bash
uv run --isolated --no-project --python 3.13 \
  python scripts/style_presets.py --list
uv run --isolated --no-project --python 3.13 \
  python scripts/style_presets.py --show nature
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  python scripts/figure_export.py --demo outputs/export-smoke --manifest
bash
uv run --isolated --no-project --python 3.13 \
  python scripts/style_presets.py --list
uv run --isolated --no-project --python 3.13 \
  python scripts/style_presets.py --show nature
uv run --isolated --no-project --python 3.13 \
  --with "matplotlib==3.11.1" \
  python scripts/figure_export.py --demo outputs/export-smoke --manifest

Assets

Assets

  • assets/publication.mplstyle
    : general print starting point.
  • assets/nature.mplstyle
    : dated flagship Nature visual starting point, not a compliance preset.
  • assets/presentation.mplstyle
    : larger projected-display style.
  • assets/color_palettes.py
    : importable Okabe-Ito and Paul Tol values with metadata.
  • assets/publisher_profiles.json
    : dated, machine-readable planning snapshots.
Matplotlib style files omit
#
in hex colors because
#
begins comments in
.mplstyle
parsing.
  • assets/publication.mplstyle
    :通用打印起点。
  • assets/nature.mplstyle
    :带日期的 Nature 旗舰视觉起点,而不是合规预设。
  • assets/presentation.mplstyle
    :适用于更大投影显示的样式。
  • assets/color_palettes.py
    :可导入的 Okabe-Ito 和 Paul Tol 配色值及元数据。
  • assets/publisher_profiles.json
    :带日期的机器可读规划快照。
Matplotlib 样式文件中的十六进制颜色省略
#
,因为在
.mplstyle
解析中
#
表示注释开头。

References

References

  • references/publication_guidelines.md
    : integrity, deceptive encodings, accessibility, static/interactive output.
  • references/color_palettes.md
    : palette semantics, exact values, WCAG contrast, grayscale caveats, color management.
  • references/journal_requirements.md
    : phase-specific official publisher snapshots.
  • references/matplotlib_examples.md
    : current, runnable Matplotlib/Seaborn/Plotly patterns.
  • references/sources.md
    : official URLs, dates, versions, and research basis.
  • references/publication_guidelines.md
    :完整性、欺骗性编码、无障碍性以及静态/交互式输出。
  • references/color_palettes.md
    :调色板语义、精确值、WCAG 对比度、灰度注意事项和色彩管理。
  • references/journal_requirements.md
    :针对不同投稿阶段的官方出版商快照。
  • references/matplotlib_examples.md
    :当前可运行的 Matplotlib/Seaborn/Plotly 模式。
  • references/sources.md
    :官方 URL、日期、版本和研究依据。

Final review checklist

最终审核清单

  • Raw data/images and transformation code are preserved.
  • Missing values, exclusions, bins, normalization, and uncertainty are explicit.
  • Baselines, scales, limits, and area/volume encodings are honest.
  • Color is redundant and rendered contrast was reviewed.
  • Figure has an accessible description/data alternative where applicable.
  • Physical dimensions, DPI, format, fonts, transparency, and file size were inspected after export.
  • Publisher rules were verified for the exact journal and phase.
  • No automated report is presented as a scientific, accessibility, or compliance certification.
  • 保留原始数据/图像和转换代码。
  • 明确呈现缺失值、排除项、分箱、归一化和不确定性。
  • 诚实呈现基线、尺度、范围以及面积/体积编码。
  • 颜色编码具有冗余性,且已审查渲染后的对比度。
  • 在适用情况下,图表提供无障碍描述或数据替代方案。
  • 导出后检查物理尺寸、DPI、格式、字体、透明度和文件大小。
  • 针对具体期刊和投稿阶段核实出版商规则。
  • 不将任何自动报告表述为科学、无障碍或合规性认证。

Related skills

相关 skill

  • matplotlib
    : Low-level plotting library for full customization.
  • academic-plotting
    : Generates publication-quality figures for ML papers from research context.
  • seaborn
    : Statistical visualization with pandas integration.
  • matplotlib
    :用于完全自定义的低级绘图库。
  • academic-plotting
    :根据研究上下文为 ML 论文生成达到出版质量的图表。
  • seaborn
    :与 pandas 集成的统计可视化工具。