Scientific Visualization
Overview
Scientific visualization transforms data into clear, accurate figures for publication. Create journal-ready plots with multi-panel layouts, error bars, significance markers, and colorblind-safe palettes. Export as PDF/EPS/TIFF using matplotlib, seaborn, and plotly for manuscripts.
When to Use This Skill
This skill should be used when:
- - Creating plots or visualizations for scientific manuscripts
- Preparing figures for journal submission (Nature, Science, Cell, PLOS, etc.)
- Ensuring figures are colorblind-friendly and accessible
- Making multi-panel figures with consistent styling
- Exporting figures at correct resolution and format
- Following specific publication guidelines
- Improving existing figures to meet publication standards
- Creating figures that need to work in both color and grayscale
Quick Start Guide
Basic Publication-Quality Figure
CODEBLOCK0
Using Pre-configured Styles
Apply journal-specific styles using the matplotlib style files in assets/:
CODEBLOCK1
Quick Start with Seaborn
For statistical plots, use seaborn with publication styling:
CODEBLOCK2
Core Principles and Best Practices
1. Resolution and File Format
Critical requirements (detailed in references/publication_guidelines.md):
- - Raster images (photos, microscopy): 300-600 DPI
- Line art (graphs, plots): 600-1200 DPI or vector format
- Vector formats (preferred): PDF, EPS, SVG
- Raster formats: TIFF, PNG (never JPEG for scientific data)
Implementation:
CODEBLOCK3
2. Color Selection - Colorblind Accessibility
Always use colorblind-friendly palettes (detailed in references/color_palettes.md):
Recommended: Okabe-Ito palette (distinguishable by all types of color blindness):
CODEBLOCK4
For heatmaps/continuous data:
- - Use perceptually uniform colormaps:
viridis, plasma, INLINECODE5 - Avoid red-green diverging maps (use
PuOr, RdBu, BrBG instead) - Never use
jet or rainbow colormaps
Always test figures in grayscale to ensure interpretability.
3. Typography and Text
Font guidelines (detailed in references/publication_guidelines.md):
- - Sans-serif fonts: Arial, Helvetica, Calibri
- Minimum sizes at final print size:
- Axis labels: 7-9 pt
- Tick labels: 6-8 pt
- Panel labels: 8-12 pt (bold)
- - Sentence case for labels: "Time (hours)" not "TIME (HOURS)"
- Always include units in parentheses
Implementation:
CODEBLOCK5
4. Figure Dimensions
Journal-specific widths (detailed in references/journal_requirements.md):
- - Nature: Single 89 mm, Double 183 mm
- Science: Single 55 mm, Double 175 mm
- Cell: Single 85 mm, Double 178 mm
Check figure size compliance:
CODEBLOCK6
5. Multi-Panel Figures
Best practices:
- - Label panels with bold letters: A, B, C (uppercase for most journals, lowercase for Nature)
- Maintain consistent styling across all panels
- Align panels along edges where possible
- Use adequate white space between panels
Example implementation (see references/matplotlib_examples.md for complete code):
CODEBLOCK7
Common Tasks
Task 1: Create a Publication-Ready Line Plot
See references/matplotlib_examples.md Example 1 for complete code.
Key steps:
- 1. Apply publication style
- Set appropriate figure size for target journal
- Use colorblind-friendly colors
- Add error bars with correct representation (SEM, SD, or CI)
- Label axes with units
- Remove unnecessary spines
- Save in vector format
Using seaborn for automatic confidence intervals:
CODEBLOCK8
Task 2: Create a Multi-Panel Figure
See references/matplotlib_examples.md Example 2 for complete code.
Key steps:
- 1. Use
GridSpec for flexible layout - Ensure consistent styling across panels
- Add bold panel labels (A, B, C, etc.)
- Align related panels
- Verify all text is readable at final size
Task 3: Create a Heatmap with Proper Colormap
See references/matplotlib_examples.md Example 4 for complete code.
Key steps:
- 1. Use perceptually uniform colormap (
viridis, plasma, cividis) - Include labeled colorbar
- For diverging data, use colorblind-safe diverging map (
RdBu_r, PuOr) - Set appropriate center value for diverging maps
- Test appearance in grayscale
Using seaborn for correlation matrices:
CODEBLOCK9
Task 4: Prepare Figure for Specific Journal
Workflow:
- 1. Check journal requirements: INLINECODE23
- Configure matplotlib for journal:
from style_presets import configure_for_journal
configure_for_journal('nature', figure_width='single')
- 3. Create figure (will auto-size correctly)
- Export with journal specifications:
CODEBLOCK11
Task 5: Fix an Existing Figure to Meet Publication Standards
Checklist approach (full checklist in references/publication_guidelines.md):
- 1. Check resolution: Verify DPI meets journal requirements
- Check file format: Use vector for plots, TIFF/PNG for images
- Check colors: Ensure colorblind-friendly
- Check fonts: Minimum 6-7 pt at final size, sans-serif
- Check labels: All axes labeled with units
- Check size: Matches journal column width
- Test grayscale: Figure interpretable without color
- Remove chart junk: No unnecessary grids, 3D effects, shadows
Task 6: Create Colorblind-Friendly Visualizations
Strategy:
- 1. Use approved palettes from INLINECODE25
- Add redundant encoding (line styles, markers, patterns)
- Test with colorblind simulator
- Ensure grayscale compatibility
Example:
CODEBLOCK12
Statistical Rigor
Always include:
- - Error bars (SD, SEM, or CI - specify which in caption)
- Sample size (n) in figure or caption
- Statistical significance markers (, , )
- Individual data points when possible (not just summary statistics)
Example with statistics:
CODEBLOCK13
Working with Different Plotting Libraries
Matplotlib
- - Most control over publication details
- Best for complex multi-panel figures
- Use provided style files for consistent formatting
- See
references/matplotlib_examples.md for extensive examples
Seaborn
Seaborn provides a high-level, dataset-oriented interface for statistical graphics, built on matplotlib. It excels at creating publication-quality statistical visualizations with minimal code while maintaining full compatibility with matplotlib customization.
Key advantages for scientific visualization:
- - Automatic statistical estimation and confidence intervals
- Built-in support for multi-panel figures (faceting)
- Colorblind-friendly palettes by default
- Dataset-oriented API using pandas DataFrames
- Semantic mapping of variables to visual properties
Quick Start with Publication Style
Always apply matplotlib publication styles first, then configure seaborn:
CODEBLOCK14
Common Plot Types for Publications
Statistical comparisons:
CODEBLOCK15
Distribution analysis:
CODEBLOCK16
Correlation matrices:
CODEBLOCK17
Time series with confidence bands:
CODEBLOCK18
Multi-Panel Figures with Seaborn
Using FacetGrid for automatic faceting:
CODEBLOCK19
Combining seaborn with matplotlib subplots:
CODEBLOCK20
Color Palettes for Publications
Seaborn includes several colorblind-safe palettes:
CODEBLOCK21
Choosing Between Axes-Level and Figure-Level Functions
Axes-level functions (e.g., scatterplot, boxplot, heatmap):
- - Use when building custom multi-panel layouts
- Accept
ax= parameter for precise placement - Better integration with matplotlib subplots
- More control over figure composition
CODEBLOCK22
Figure-level functions (e.g., relplot, catplot, displot):
- - Use for automatic faceting by categorical variables
- Create complete figures with consistent styling
- Great for exploratory analysis
- Use
height and aspect for sizing
CODEBLOCK23
Statistical Rigor with Seaborn
Seaborn automatically computes and displays uncertainty:
CODEBLOCK24
Best Practices for Publication-Ready Seaborn Figures
- 1. Always set publication theme first:
CODEBLOCK25
- 2. Use colorblind-safe palettes:
CODEBLOCK26
- 3. Remove unnecessary elements:
CODEBLOCK27
- 4. Control figure size appropriately:
CODEBLOCK28
- 5. Show individual data points when possible:
CODEBLOCK29
- 6. Include proper labels with units:
CODEBLOCK30
- 7. Export at correct resolution:
CODEBLOCK31
Advanced Seaborn Techniques
Pairwise relationships for exploratory analysis:
CODEBLOCK32
Hierarchical clustering heatmap:
CODEBLOCK33
Joint distributions with marginals:
CODEBLOCK34
Common Seaborn Issues and Solutions
Issue: Legend outside plot area
CODEBLOCK35
Issue: Overlapping labels
CODEBLOCK36
Issue: Text too small at final size
CODEBLOCK37
Additional Resources
For more detailed seaborn information, see:
- -
scientific-packages/seaborn/SKILL.md - Comprehensive seaborn documentation - INLINECODE37 - Practical use cases
- INLINECODE38 - Complete API reference
- INLINECODE39 - Modern declarative API
Plotly
- - Interactive figures for exploration
- Export static images for publication
- Configure for publication quality:
CODEBLOCK38
Resources
References Directory
Load these as needed for detailed information:
- -
publication_guidelines.md: Comprehensive best practices
- Resolution and file format requirements
- Typography guidelines
- Layout and composition rules
- Statistical rigor requirements
- Complete publication checklist
- -
color_palettes.md: Color usage guide
- Colorblind-friendly palette specifications with RGB values
- Sequential and diverging colormap recommendations
- Testing procedures for accessibility
- Domain-specific palettes (genomics, microscopy)
- -
journal_requirements.md: Journal-specific specifications
- Technical requirements by publisher
- File format and DPI specifications
- Figure dimension requirements
- Quick reference table
- -
matplotlib_examples.md: Practical code examples
- 10 complete working examples
- Line plots, bar plots, heatmaps, multi-panel figures
- Journal-specific figure examples
- Tips for each library (matplotlib, seaborn, plotly)
Scripts Directory
Use these helper scripts for automation:
- -
figure_export.py: Export utilities
-
save_publication_figure(): Save in multiple formats with correct DPI
-
save_for_journal(): Use journal-specific requirements automatically
-
check_figure_size(): Verify dimensions meet journal specs
- Run directly:
python scripts/figure_export.py for examples
- -
style_presets.py: Pre-configured styles
-
apply_publication_style(): Apply preset styles (default, nature, science, cell)
-
set_color_palette(): Quick palette switching
-
configure_for_journal(): One-command journal configuration
- Run directly:
python scripts/style_presets.py to see examples
Assets Directory
Use these files in figures:
- -
color_palettes.py: Importable color definitions
- All recommended palettes as Python constants
-
apply_palette() helper function
- Can be imported directly into notebooks/scripts
- - Matplotlib style files: Use with INLINECODE56
-
publication.mplstyle: General publication quality
-
nature.mplstyle: Nature journal specifications
-
presentation.mplstyle: Larger fonts for posters/slides
Workflow Summary
Recommended workflow for creating publication figures:
- 1. Plan: Determine target journal, figure type, and content
- Configure: Apply appropriate style for journal
from style_presets import configure_for_journal
configure_for_journal('nature', 'single')
- 3. Create: Build figure with proper labels, colors, statistics
- Verify: Check size, fonts, colors, accessibility
from figure_export import check_figure_size
check_figure_size(fig, journal='nature')
- 5. Export: Save in required formats
from figure_export import save_for_journal
save_for_journal(fig, 'figure1', 'nature', 'combination')
- 6. Review: View at final size in manuscript context
Common Pitfalls to Avoid
- 1. Font too small: Text unreadable when printed at final size
- JPEG format: Never use JPEG for graphs/plots (creates artifacts)
- Red-green colors: ~8% of males cannot distinguish
- Low resolution: Pixelated figures in publication
- Missing units: Always label axes with units
- 3D effects: Distorts perception, avoid completely
- Chart junk: Remove unnecessary gridlines, decorations
- Truncated axes: Start bar charts at zero unless scientifically justified
- Inconsistent styling: Different fonts/colors across figures in same manuscript
- No error bars: Always show uncertainty
Final Checklist
Before submitting figures, verify:
- - [ ] Resolution meets journal requirements (300+ DPI)
- [ ] File format is correct (vector for plots, TIFF for images)
- [ ] Figure size matches journal specifications
- [ ] All text readable at final size (≥6 pt)
- [ ] Colors are colorblind-friendly
- [ ] Figure works in grayscale
- [ ] All axes labeled with units
- [ ] Error bars present with definition in caption
- [ ] Panel labels present and consistent
- [ ] No chart junk or 3D effects
- [ ] Fonts consistent across all figures
- [ ] Statistical significance clearly marked
- [ ] Legend is clear and complete
Use this skill to ensure scientific figures meet the highest publication standards while remaining accessible to all readers.
科学可视化
概述
科学可视化将数据转化为清晰、准确的图形以供发表。创建包含多面板布局、误差线、显著性标记和色盲友好调色板的期刊级图表。使用matplotlib、seaborn和plotly导出为PDF/EPS/TIFF格式,用于手稿提交。
何时使用此技能
此技能应在以下情况使用:
- - 为科学手稿创建图表或可视化
- 准备提交期刊(Nature、Science、Cell、PLOS等)的图表
- 确保图表对色盲友好且可访问
- 制作风格一致的多面板图表
- 以正确的分辨率和格式导出图表
- 遵循特定的出版指南
- 改进现有图表以达到出版标准
- 创建需在彩色和灰度模式下均适用的图表
快速入门指南
基础出版级图表
python
import matplotlib.pyplot as plt
import numpy as np
应用出版风格(来自scripts/style_presets.py)
from style
presets import applypublication_style
apply
publicationstyle(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(时间(秒))
ax.set_ylabel(振幅(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 savepublication_figure
save
publicationfigure(fig, figure1, formats=[pdf, png], dpi=300)
使用预配置风格
使用assets/中的matplotlib风格文件应用期刊特定风格:
python
import matplotlib.pyplot as plt
选项1:直接使用风格文件
plt.style.use(assets/nature.mplstyle)
选项2:使用style_presets.py辅助函数
from style
presets import configurefor_journal
configure
forjournal(nature, figure_width=single)
现在创建图表——它们将自动匹配Nature规范
fig, ax = plt.subplots()
... 您的绘图代码 ...
使用Seaborn快速入门
对于统计图表,使用带出版风格的seaborn:
python
import seaborn as sns
import matplotlib.pyplot as plt
from stylepresets import applypublication_style
应用出版风格
apply
publicationstyle(default)
sns.set
theme(style=ticks, context=paper, fontscale=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(响应(μM))
sns.despine()
保存图表
from figure
export import savepublication_figure
save
publicationfigure(fig, treatment_comparison, formats=[pdf, png], dpi=300)
核心原则与最佳实践
1. 分辨率与文件格式
关键要求(详见references/publication_guidelines.md):
- - 栅格图像(照片、显微镜):300-600 DPI
- 线条图(图表、图形):600-1200 DPI或矢量格式
- 矢量格式(首选):PDF、EPS、SVG
- 栅格格式:TIFF、PNG(科学数据切勿使用JPEG)
实现:
python
使用figure_export.py脚本获取正确设置
from figure
export import savepublication_figure
以多种格式和正确DPI保存
save
publicationfigure(fig, myfigure, formats=[pdf, png], dpi=300)
或按特定期刊要求保存
from figure
export import savefor_journal
save
forjournal(fig, figure1, journal=nature, figure_type=combination)
2. 颜色选择——色盲可访问性
始终使用色盲友好调色板(详见references/color_palettes.md):
推荐:Okabe-Ito调色板(所有色盲类型均可区分):
python
选项1:使用assets/color_palettes.py
from color
palettes import OKABEITO
LIST, applypalette
apply
palette(okabeito)
选项2:手动指定
okabe_ito = [#E69F00, #56B4E9, #009E73, #F0E442,
#0072B2, #D55E00, #CC79A7, #000000]
plt.rcParams[axes.prop
cycle] = plt.cycler(color=okabeito)
对于热图/连续数据:
- - 使用感知均匀的颜色映射:viridis、plasma、cividis
- 避免红-绿发散映射(改用PuOr、RdBu、BrBG)
- 切勿使用jet或rainbow颜色映射
始终在灰度模式下测试图表以确保可解释性。
3. 排版与文本
字体指南(详见references/publication_guidelines.md):
- - 无衬线字体:Arial、Helvetica、Calibri
- 最终打印尺寸下的最小字号:
- 轴标签:7-9 pt
- 刻度标签:6-8 pt
- 面板标签:8-12 pt(加粗)
- - 标签使用句首大写:Time (hours)而非TIME (HOURS)
- 始终在括号中包含单位
实现:
python
全局设置字体
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
4. 图表尺寸
期刊特定宽度(详见references/journal_requirements.md):
- - Nature:单栏89 mm,双栏183 mm
- Science:单栏55 mm,双栏175 mm
- Cell:单栏85 mm,双栏178 mm
检查图表尺寸合规性:
python
from figureexport import checkfigure_size
fig = plt.figure(figsize=(3.5, 3)) # Nature的89 mm
checkfiguresize(fig, journal=nature)
5. 多面板图表
最佳实践:
- - 用加粗字母标注面板:A、B、C(大多数期刊用大写,Nature用小写)
- 保持所有面板风格一致
- 尽可能沿边缘对齐面板
- 面板之间留出足够的空白
示例实现(完整代码见references/matplotlib_examples.md):
python
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])
... 创建其他面板 ...
添加面板标签
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)
常见任务
任务1:创建出版级线图
完整代码见references/matplotlib_examples.md示例1。
关键步骤:
- 1. 应用出版风格
- 为目标期刊设置合适的图表尺寸
- 使用色盲友好颜色
- 添加正确表示的误差线(SEM、SD或CI)
- 标注带单位的轴
- 移除不必要的边框
7.