一键导入
scientific-visualization
面向发表级图表的元技能。适用于需要多面板布局、显著性标注、误差线、色盲安全配色和特定期刊格式要求的投稿图表。协调 matplotlib、seaborn、plotly 及其发表风格;若只是快速探索,直接使用 seaborn 或 plotly 即可。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
面向发表级图表的元技能。适用于需要多面板布局、显著性标注、误差线、色盲安全配色和特定期刊格式要求的投稿图表。协调 matplotlib、seaborn、plotly 及其发表风格;若只是快速探索,直接使用 seaborn 或 plotly 即可。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | scientific-visualization |
| description | 面向发表级图表的元技能。适用于需要多面板布局、显著性标注、误差线、色盲安全配色和特定期刊格式要求的投稿图表。协调 matplotlib、seaborn、plotly 及其发表风格;若只是快速探索,直接使用 seaborn 或 plotly 即可。 |
| license | MIT license |
| metadata | {"skill-author":"K-Dense Inc.","acadclaw":{"profiles":["coder"],"produces":["plots"],"consumes":["experiment_results"]}} |
科学可视化的目标,是把数据转成适合发表的清晰、准确图表。它强调多面板布局、误差线、显著性标记与色盲安全配色,并支持使用 matplotlib、seaborn、plotly 导出 PDF、EPS、TIFF 等投稿格式。
当你遇到以下场景时,应优先使用这个技能:
import matplotlib.pyplot as plt
import numpy as np
# 应用发表风格(来自 scripts/style_presets.py)
from style_presets import apply_publication_style
apply_publication_style('default')
# 创建合适尺寸的图(单栏约 3.5 英寸)
fig, ax = plt.subplots(figsize=(3.5, 2.5))
# 绘制数据
x = np.linspace(0, 10, 100)
ax.plot(x, np.sin(x), label='sin(x)')
ax.plot(x, np.cos(x), label='cos(x)')
# 设置带单位的规范标签
ax.set_xlabel('Time (seconds)')
ax.set_ylabel('Amplitude (mV)')
ax.legend(frameon=False)
# 去除不必要的边框线
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# 按投稿格式保存(来自 scripts/figure_export.py)
from figure_export import save_publication_figure
save_publication_figure(fig, 'figure1', formats=['pdf', 'png'], dpi=300)
可通过 assets/ 中的 matplotlib 样式文件套用特定期刊风格:
import matplotlib.pyplot as plt
# 方式 1:直接使用样式文件
plt.style.use('assets/nature.mplstyle')
# 方式 2:使用 style_presets.py 辅助函数
from style_presets import configure_for_journal
configure_for_journal('nature', figure_width='single')
# 之后创建的图会自动匹配 Nature 常见规范
fig, ax = plt.subplots()
# ... your plotting code ...
统计图更适合结合 seaborn 和投稿风格一起使用:
import seaborn as sns
import matplotlib.pyplot as plt
from style_presets import apply_publication_style
# 应用投稿风格
apply_publication_style('default')
sns.set_theme(style='ticks', context='paper', font_scale=1.1)
sns.set_palette('colorblind')
# 创建统计对比图
fig, ax = plt.subplots(figsize=(3.5, 3))
sns.boxplot(data=df, x='treatment', y='response',
order=['Control', 'Low', 'High'], palette='Set2', ax=ax)
sns.stripplot(data=df, x='treatment', y='response',
order=['Control', 'Low', 'High'],
color='black', alpha=0.3, size=3, ax=ax)
ax.set_ylabel('Response (μM)')
sns.despine()
# 保存图件
from figure_export import save_publication_figure
save_publication_figure(fig, 'treatment_comparison', formats=['pdf', 'png'], dpi=300)
关键要求(详见 references/publication_guidelines.md):
实现方式:
# 使用 figure_export.py 获得正确导出设置
from figure_export import save_publication_figure
# 以正确 DPI 导出多种格式
save_publication_figure(fig, 'myfigure', formats=['pdf', 'png'], dpi=300)
# 或按特定期刊要求导出
from figure_export import save_for_journal
save_for_journal(fig, 'figure1', journal='nature', figure_type='combination')
始终使用色盲友好配色(详见 references/color_palettes.md):
推荐:Okabe-Ito 配色(对常见色觉缺陷都较易区分):
# 方式 1:使用 assets/color_palettes.py
from color_palettes import OKABE_ITO_LIST, apply_palette
apply_palette('okabe_ito')
# 方式 2:手动指定
okabe_ito = ['#E69F00', '#56B4E9', '#009E73', '#F0E442',
'#0072B2', '#D55E00', '#CC79A7', '#000000']
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=okabe_ito)
对于热图 / 连续数据:
viridis、plasma、cividisPuOr、RdBu、BrBGjet 或 rainbow 色图始终在灰度条件下测试图件,确保不依赖颜色也能读懂。
字体规范(详见 references/publication_guidelines.md):
Time (hours),而不是 TIME (HOURS)实现方式:
# 全局设置字体
import matplotlib as mpl
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = ['Arial', 'Helvetica']
mpl.rcParams['font.size'] = 8
mpl.rcParams['axes.labelsize'] = 9
mpl.rcParams['xtick.labelsize'] = 7
mpl.rcParams['ytick.labelsize'] = 7
期刊常见宽度(详见 references/journal_requirements.md):
检查图尺寸是否合规:
from figure_export import check_figure_size
fig = plt.figure(figsize=(3.5, 3)) # 89 mm for Nature
check_figure_size(fig, journal='nature')
最佳实践:
示例实现(完整代码见 references/matplotlib_examples.md):
from string import ascii_uppercase
fig = plt.figure(figsize=(7, 4))
gs = fig.add_gridspec(2, 2, hspace=0.4, wspace=0.4)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
# ... create other panels ...
# 添加面板标签
for i, ax in enumerate([ax1, ax2, ...]):
ax.text(-0.15, 1.05, ascii_uppercase[i], transform=ax.transAxes,
fontsize=10, fontweight='bold', va='top')
完整代码见 references/matplotlib_examples.md 的 Example 1。
关键步骤:
如果使用 seaborn 自动绘制置信区间:
import seaborn as sns
fig, ax = plt.subplots(figsize=(5, 3))
sns.lineplot(data=timeseries, x='time', y='measurement',
hue='treatment', errorbar=('ci', 95),
markers=True, ax=ax)
ax.set_xlabel('Time (hours)')
ax.set_ylabel('Measurement (AU)')
sns.despine()
完整代码见 references/matplotlib_examples.md 的 Example 2。
关键步骤:
GridSpec 构造灵活布局完整代码见 references/matplotlib_examples.md 的 Example 4。
关键步骤:
viridis、plasma、cividis)RdBu_r、PuOr)如果用 seaborn 绘制相关矩阵:
import seaborn as sns
fig, ax = plt.subplots(figsize=(5, 4))
corr = df.corr()
mask = np.triu(np.ones_like(corr, dtype=bool))
sns.heatmap(corr, mask=mask, annot=True, fmt='.2f',
cmap='RdBu_r', center=0, square=True,
linewidths=1, cbar_kws={'shrink': 0.8}, ax=ax)
工作流:
references/journal_requirements.mdfrom style_presets import configure_for_journal
configure_for_journal('nature', figure_width='single')
from figure_export import save_for_journal
save_for_journal(fig, 'figure1', journal='nature', figure_type='line_art')
清单式检查法(完整清单见 references/publication_guidelines.md):
策略:
assets/color_palettes.py 中已验证的配色示例:
from color_palettes import apply_palette
import matplotlib.pyplot as plt
apply_palette('okabe_ito')
# 在颜色之外增加冗余编码
line_styles = ['-', '--', '-.', ':']
markers = ['o', 's', '^', 'v']
for i, (data, label) in enumerate(datasets):
plt.plot(x, data, linestyle=line_styles[i % 4],
marker=markers[i % 4], label=label)
通常应包含:
n(图中或图注中给出)*、**、***)统计示例:
# 同时展示单点与汇总统计
ax.scatter(x_jittered, individual_points, alpha=0.4, s=8)
ax.errorbar(x, means, yerr=sems, fmt='o', capsize=3)
# 标记显著性
ax.text(1.5, max_y * 1.1, '***', ha='center', fontsize=8)
references/matplotlib_examples.mdSeaborn 是建立在 matplotlib 之上的高层统计绘图库,偏向数据集导向接口。它非常适合用较少代码快速生成投稿质量的统计图,同时保留与 matplotlib 定制能力的兼容性。
在科学可视化中的主要优势:
建议先应用 matplotlib 的投稿风格,再配置 seaborn:
import seaborn as sns
import matplotlib.pyplot as plt
from style_presets import apply_publication_style
# 应用投稿风格
apply_publication_style('default')
# 配置 seaborn 用于投稿图
sns.set_theme(style='ticks', context='paper', font_scale=1.1)
sns.set_palette('colorblind') # Use colorblind-safe palette
# 创建图形
fig, ax = plt.subplots(figsize=(3.5, 2.5))
sns.scatterplot(data=df, x='time', y='response',
hue='treatment', style='condition', ax=ax)
sns.despine() # Remove top and right spines
统计比较图:
# 用箱线图叠加单点,提升透明度
fig, ax = plt.subplots(figsize=(3.5, 3))
sns.boxplot(data=df, x='treatment', y='response',
order=['Control', 'Low', 'High'], palette='Set2', ax=ax)
sns.stripplot(data=df, x='treatment', y='response',
order=['Control', 'Low', 'High'],
color='black', alpha=0.3, size=3, ax=ax)
ax.set_ylabel('Response (μM)')
sns.despine()
分布分析图:
# 分裂式小提琴图,用于比较两组分布
fig, ax = plt.subplots(figsize=(4, 3))
sns.violinplot(data=df, x='timepoint', y='expression',
hue='treatment', split=True, inner='quartile', ax=ax)
ax.set_ylabel('Gene Expression (AU)')
sns.despine()
相关矩阵:
# 使用合适色图与标注的热图
fig, ax = plt.subplots(figsize=(5, 4))
corr = df.corr()
mask = np.triu(np.ones_like(corr, dtype=bool)) # Show only lower triangle
sns.heatmap(corr, mask=mask, annot=True, fmt='.2f',
cmap='RdBu_r', center=0, square=True,
linewidths=1, cbar_kws={'shrink': 0.8}, ax=ax)
plt.tight_layout()
带置信带的时间序列图:
# 自动计算置信区间的折线图
fig, ax = plt.subplots(figsize=(5, 3))
sns.lineplot(data=timeseries, x='time', y='measurement',
hue='treatment', style='replicate',
errorbar=('ci', 95), markers=True, dashes=False, ax=ax)
ax.set_xlabel('Time (hours)')
ax.set_ylabel('Measurement (AU)')
sns.despine()
使用 FacetGrid 自动分面:
# 创建分面图
g = sns.relplot(data=df, x='dose', y='response',
hue='treatment', col='cell_line', row='timepoint',
kind='line', height=2.5, aspect=1.2,
errorbar=('ci', 95), markers=True)
g.set_axis_labels('Dose (μM)', 'Response (AU)')
g.set_titles('{row_name} | {col_name}')
sns.despine()
# 按正确 DPI 保存
from figure_export import save_publication_figure
save_publication_figure(g.figure, 'figure_facets',
formats=['pdf', 'png'], dpi=300)
把 seaborn 与 matplotlib 子图结合使用:
# 创建自定义多面板布局
fig, axes = plt.subplots(2, 2, figsize=(7, 6))
# 面板 A:带回归线的散点图
sns.regplot(data=df, x='predictor', y='response', ax=axes[0, 0])
axes[0, 0].text(-0.15, 1.05, 'A', transform=axes[0, 0].transAxes,
fontsize=10, fontweight='bold')
# 面板 B:分布对比图
sns.violinplot(data=df, x='group', y='value', ax=axes[0, 1])
axes[0, 1].text(-0.15, 1.05, 'B', transform=axes[0, 1].transAxes,
fontsize=10, fontweight='bold')
# 面板 C:热图
sns.heatmap(correlation_data, cmap='viridis', ax=axes[1, 0])
axes[1, 0].text(-0.15, 1.05, 'C', transform=axes[1, 0].transAxes,
fontsize=10, fontweight='bold')
# 面板 D:时间序列图
sns.lineplot(data=timeseries, x='time', y='signal',
hue='condition', ax=axes[1, 1])
axes[1, 1].text(-0.15, 1.05, 'D', transform=axes[1, 1].transAxes,
fontsize=10, fontweight='bold')
plt.tight_layout()
sns.despine()
Seaborn 内置了多种色盲友好配色:
# 使用内置 colorblind 配色(推荐)
sns.set_palette('colorblind')
# 或指定自定义色盲友好配色(Okabe-Ito)
okabe_ito = ['#E69F00', '#56B4E9', '#009E73', '#F0E442',
'#0072B2', '#D55E00', '#CC79A7', '#000000']
sns.set_palette(okabe_ito)
# 热图和连续数据的色图示例
sns.heatmap(data, cmap='viridis') # Perceptually uniform
sns.heatmap(corr, cmap='RdBu_r', center=0) # Diverging, centered
Axes-level functions(如 scatterplot、boxplot、heatmap):
ax= 精确指定位置fig, ax = plt.subplots(figsize=(3.5, 2.5))
sns.scatterplot(data=df, x='x', y='y', hue='group', ax=ax)
Figure-level functions(如 relplot、catplot、displot):
height and aspect for sizingg = sns.relplot(data=df, x='x', y='y', col='category', kind='scatter')
Seaborn automatically computes and displays uncertainty:
# Line plot: shows mean ± 95% CI by default
sns.lineplot(data=df, x='time', y='value', hue='treatment',
errorbar=('ci', 95)) # Can change to 'sd', 'se', etc.
# Bar plot: shows mean with bootstrapped CI
sns.barplot(data=df, x='treatment', y='response',
errorbar=('ci', 95), capsize=0.1)
# Always specify error type in figure caption:
# "Error bars represent 95% confidence intervals"
Always set publication theme first:
sns.set_theme(style='ticks', context='paper', font_scale=1.1)
Use colorblind-safe palettes:
sns.set_palette('colorblind')
Remove unnecessary elements:
sns.despine() # Remove top and right spines
Control figure size appropriately:
# Axes-level: use matplotlib figsize
fig, ax = plt.subplots(figsize=(3.5, 2.5))
# Figure-level: use height and aspect
g = sns.relplot(..., height=3, aspect=1.2)
Show individual data points when possible:
sns.boxplot(...) # Summary statistics
sns.stripplot(..., alpha=0.3) # Individual points
Include proper labels with units:
ax.set_xlabel('Time (hours)')
ax.set_ylabel('Expression (AU)')
Export at correct resolution:
from figure_export import save_publication_figure
save_publication_figure(fig, 'figure_name',
formats=['pdf', 'png'], dpi=300)
Pairwise relationships for exploratory analysis:
# Quick overview of all relationships
g = sns.pairplot(data=df, hue='condition',
vars=['gene1', 'gene2', 'gene3'],
corner=True, diag_kind='kde', height=2)
Hierarchical clustering heatmap:
# Cluster samples and features
g = sns.clustermap(expression_data, method='ward',
metric='euclidean', z_score=0,
cmap='RdBu_r', center=0,
figsize=(10, 8),
row_colors=condition_colors,
cbar_kws={'label': 'Z-score'})
Joint distributions with marginals:
# Bivariate distribution with context
g = sns.jointplot(data=df, x='gene1', y='gene2',
hue='treatment', kind='scatter',
height=6, ratio=4, marginal_kws={'kde': True})
Issue: Legend outside plot area
g = sns.relplot(...)
g._legend.set_bbox_to_anchor((0.9, 0.5))
Issue: Overlapping labels
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
Issue: Text too small at final size
sns.set_context('paper', font_scale=1.2) # Increase if needed
For more detailed seaborn information, see:
scientific-packages/seaborn/SKILL.md - Comprehensive seaborn documentationscientific-packages/seaborn/references/examples.md - Practical use casesscientific-packages/seaborn/references/function_reference.md - Complete API referencescientific-packages/seaborn/references/objects_interface.md - Modern declarative APIfig.update_layout(
font=dict(family='Arial, sans-serif', size=10),
plot_bgcolor='white',
# ... see matplotlib_examples.md Example 8
)
fig.write_image('figure.png', scale=3) # scale=3 gives ~300 DPI
按需加载以下文档以获取详细信息:
publication_guidelines.md: 综合最佳实践
color_palettes.md: 配色使用指南
journal_requirements.md: 期刊专属技术规范
matplotlib_examples.md: 实用代码示例
使用这些辅助脚本完成自动化处理:
figure_export.py: 导出工具
save_publication_figure(): 按正确 DPI 导出多种格式save_for_journal(): 自动套用期刊专属要求check_figure_size(): 校验图件尺寸是否符合期刊规范python scripts/figure_export.py 查看示例style_presets.py: 预配置样式
apply_publication_style(): 应用预设样式(default、nature、science、cell)set_color_palette(): 快速切换配色configure_for_journal(): 一条命令完成期刊配置python scripts/style_presets.py 查看示例在图件中使用以下资源文件:
color_palettes.py: 可导入的颜色定义
apply_palette() 辅助函数Matplotlib 样式文件:可配合 plt.style.use() 使用
publication.mplstyle: 通用投稿质量样式nature.mplstyle: Nature 期刊规范样式presentation.mplstyle: 适合海报或幻灯片的大字号样式推荐的投稿图件工作流:
from style_presets import configure_for_journal
configure_for_journal('nature', 'single')
from figure_export import check_figure_size
check_figure_size(fig, journal='nature')
from figure_export import save_for_journal
save_for_journal(fig, 'figure1', 'nature', 'combination')
投稿前请确认:
Use this skill to ensure scientific figures meet the highest publication standards while remaining accessible to all readers.
为 acadclaw 调度整条 ECE 学术研究链路,决定何时调用检索、综述、研究空白、实现、实验、写作、引用和评审类 skills。Full-chain pipeline with concrete tool calls for literature search, RAG, experiments, statistics, plotting, writing, review, and citation management.
Specialized in writing research experiment code. Use when spawning a subagent to implement simulations, numerical models, data processing, or statistical analysis. Produces well-structured, documented Python code with proper error handling and result persistence.
学术关系构建指南。指导撰写 Cold Email、会议社交以及建立学术影响力。
Specialized in reviewing academic papers and providing structured feedback. Use when spawning a subagent for peer review, quality assessment, or iterative improvement of academic writing. Triggers: review, 审稿, feedback, critique, improve, 迭代, revise.
面向中文管理类硕士学位论文的多轮评审技能,尤其适用于 MBA、MEM、MPA,也可扩展到相近的专业型与应用研究型论文。
用于润色面向顶级计算机学术会议的研究写作(如 NeurIPS、ICLR、ICML、AAAI、IJCAI、ACL、EMNLP、NAACL、CVPR、WWW、KDD、SIGIR、CIKM 等)。当用户要求改进、润色、精修、编辑或校对学术写作时触发,包括论文草稿、摘要、引言、相关工作、方法描述、实验部分或结论部分;当用户粘贴 LaTeX 内容并请求写作帮助,或提到 camera-ready、rebuttal、paper revision、具体学术会议名称时也应触发。该技能同时支持整篇论文润色与分章节编辑。