Scientific Publication-Quality Figure Generation
A skill for creating scientific figures at Nature/Science/Cell publication level with matplotlib/seaborn.
It provides the 15 figure templates established in Exp-10 and the style settings common to all experiments.
When to Use
- When creating high-quality figures for journal submission
- When composing a multi-panel composite figure
- When DPI 300 or higher and appropriate font sizes and color palettes are required
- When figures need to comply with a journal's style guide
Quick Start
Global Style Settings
Always apply the following settings at the beginning of the script.
import matplotlib.pyplot as plt
import matplotlib as mpl
def setup_publication_style():
"""Nature/Science 品質の matplotlib rcParams を設定する。"""
plt.rcParams.update({
# フォント
"font.family": "sans-serif",
"font.sans-serif": ["Arial", "Helvetica", "DejaVu Sans"],
"font.size": 10,
"axes.titlesize": 12,
"axes.labelsize": 11,
"xtick.labelsize": 9,
"ytick.labelsize": 9,
"legend.fontsize": 9,
# 線・マーカー
"axes.linewidth": 1.2,
"lines.linewidth": 1.5,
"lines.markersize": 6,
# スパイン
"axes.spines.top": False,
"axes.spines.right": False,
# グリッド
"axes.grid": False,
# 保存設定
"savefig.dpi": 300,
"savefig.bbox": "tight",
"savefig.transparent": False,
# Figure 背景
"figure.facecolor": "white",
"axes.facecolor": "white",
})
Color palette
# Nature-inspired パレット(Exp-10)
NATURE_PALETTE = [
"#E64B35", # 赤
"#4DBBD5", # 水色
"#00A087", # 緑
"#3C5488", # 紺
"#F39B7F", # サーモン
"#8491B4", # グレー青
"#91D1C2", # ミント
"#DC9C6D", # オレンジ
]
# 材料・群カテゴリ用
MATERIAL_PALETTE = {
"Set2": "seaborn Set2(最大 8 色、差別化しやすい)",
"tab10": "matplotlib tab10(最大 10 色)",
"Paired": "seaborn Paired(最大 12 色、対比較向き)",
}
# 連続値用
CONTINUOUS_CMAPS = {
"viridis": "知覚均一(デフォルト推奨)",
"RdBu_r": "相関ヒートマップ(中心=0)",
"YlOrRd": "単方向の強度(密度、温度)",
"coolwarm": "二方向(応力の引張 vs 圧縮)",
}
Common Save Function
def save_fig(fig, filename, dpi=300, formats=("png",)):
"""図を指定された形式で保存する。"""
for fmt in formats:
filepath = f"figures/{filename}.{fmt}"
fig.savefig(filepath, dpi=dpi, bbox_inches="tight",
facecolor="white", edgecolor="none")
plt.close(fig)
Main Figure Templates
1. Violin + Strip Plot (with significance markers)
import seaborn as sns
from scipy import stats
def plot_violin_with_significance(df, x, y, pairs=None, figsize=(10, 6)):
fig, ax = plt.subplots(figsize=figsize)
sns.violinplot(data=df, x=x, y=y, palette=NATURE_PALETTE,
inner=None, alpha=0.3, ax=ax)
sns.stripplot(data=df, x=x, y=y, palette=NATURE_PALETTE,
size=3, alpha=0.5, ax=ax)
# 有意差ブラケット(pairs 指定時)
if pairs:
y_max = df[y].max()
for i, (g1, g2) in enumerate(pairs):
d1 = df[df[x] == g1][y]
d2 = df[df[x] == g2][y]
stat, pval = stats.mannwhitneyu(d1, d2)
stars = "***" if pval < 0.001 else "**" if pval < 0.01 else "*" if pval < 0.05 else "ns"
h = y_max * (1.05 + i * 0.08)
# ブラケット描画は adjustText か手動 annotate
ax.text((list(df[x].unique()).index(g1) +
list(df[x].unique()).index(g2)) / 2,
h, stars, ha="center", fontsize=12, fontweight="bold")
save_fig(fig, f"violin_{y}")
2. Forest Plot (meta-analysis style)
def plot_forest(effects, ci_lower, ci_upper, labels, figsize=(10, 8)):
fig, ax = plt.subplots(figsize=figsize)
y_pos = range(len(labels))
ax.errorbar(effects, y_pos, xerr=[np.array(effects) - np.array(ci_lower),
np.array(ci_upper) - np.array(effects)],
fmt="D", color=NATURE_PALETTE[0], markersize=8,
capsize=4, linewidth=2)
ax.axvline(0, color="gray", linestyle="--", linewidth=1)
ax.set_yticks(y_pos)
ax.set_yticklabels(labels)
ax.set_xlabel("Effect Size")
ax.set_title("Forest Plot", fontweight="bold")
save_fig(fig, "forest_plot")
3. Multi-panel Composite Figure
import matplotlib.gridspec as gridspec
def create_composite_figure(plot_functions, layout=(2, 3),
figsize=(18, 12), panel_labels=True):
"""
複数の描画関数を composite figure にまとめる。
plot_functions: [(func, kwargs), ...] のリスト
"""
fig = plt.figure(figsize=figsize)
gs = gridspec.GridSpec(*layout, figure=fig, hspace=0.35, wspace=0.3)
for i, (func, kwargs) in enumerate(plot_functions):
row, col = divmod(i, layout[1])
ax = fig.add_subplot(gs[row, col])
func(ax=ax, **kwargs)
if panel_labels:
ax.text(-0.1, 1.1, chr(65 + i), # A, B, C, ...
transform=ax.transAxes, fontsize=16,
fontweight="bold", va="top")
save_fig(fig, "composite_figure")
Figure Size Guidelines
| Purpose |
Size (inches) |
Notes |
| 1 column |
(3.5, 3.0) |
Nature 1 column width ≈ 89 mm |
| 1.5 columns |
(5.5, 4.0) |
Intermediate size |
| 2 columns |
(7.0, 5.0) |
Nature 2 column width ≈ 183 mm |
| Full page |
(7.0, 9.0) |
A4 height excluding margins |
ToolUniverse Integration
| TU Key |
Tool name |
Integration details |
biotools |
bio.tools |
Visualization tool registry search |
References
Output Files
| File |
Format |
figures/*.png |
PNG (300 DPI) |
figures/*.svg |
SVG (vector, for submission) |
figures/*.pdf |
PDF (vector, for LaTeX) |
Reference Experiments
- Exp-10: Complete set of 15 figure templates
- Exp-11〜13: Inheritance of rcParams settings and color palettes