Alterlab scientific viz

From AlterLab-IEU/AlterLab-Academic-Skills · View interactive version

Alterlab scientific viz is an AI agent skill from the GitHub repository AlterLab-IEU/AlterLab-Academic-Skills. Orchestrates matplotlib, seaborn, and plotly with opinionated publication styles to produce journal-ready figures. Use when preparing journal-submission figures that need multi-panel layouts with bold panel labels, statistical significance annotations, error bars, colorblind-safe palettes (Okabe-Ito

How to use this skill

Skill file

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:

Does NOT Trigger

| Scenario | Use Instead |

|----------|-------------|

| Building a custom plot from scratch or tuning individual artists and rcParams | alterlab-matplotlib |

| Quick exploratory statistical plot (pair plot, distributions) to eyeball data | alterlab-seaborn |

| Interactive chart with hover/zoom or a web dashboard | alterlab-plotly |

| Proofing a finished figure: data fidelity, overlapping labels, 300-dpi export check | alterlab-figure-qa |

| Schematic, flowchart, or pathway diagram | alterlab-scientific-schematics |

Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-matplotlib) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.

Quick Start Guide

Basic Publication-Quality Figure

import matplotlib.pyplot as plt
import numpy as np

# Apply publication style (from scripts/style_presets.py)
from style_presets import apply_publication_style
apply_publication_style('default')

# Create figure with appropriate size (single column = 3.5 inches)
fig, ax = plt.subplots(figsize=(3.5, 2.5))

# Plot data
x = np.linspace(0, 10, 100)
ax.plot(x, np.sin(x), label='sin(x)')
ax.plot(x, np.cos(x), label='cos(x)')

# Proper labeling with units
ax.set_xlabel('Time (seconds)')
ax.set_ylabel('Amplitude (mV)')
ax.legend(frameon=False)

# Remove unnecessary spines
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

# Save in publication formats (from scripts/figure_export.py)
from figure_export import save_publication_figure
save_publication_figure(fig, 'figure1', formats=['pdf', 'png'], dpi=300)

Using Pre-configured Styles

Apply journal-specific styles using the matplotlib style files in assets/:

import matplotlib.pyplot as plt

# Option 1: Use style file directly
plt.style.use('assets/nature.mplstyle')

# Option 2: Use style_presets.py helper
from style_presets import configure_for_journal
configure_for_journal('nature', figure_width='single')

# Now create figures - they'll automatically match Nature specifications
fig, ax = plt.subplots()
# ... your plotting code ...

Quick Start with Seaborn

For statistical plots, use seaborn with publication styling:

import seaborn as sns
import matplotlib.pyplot as plt
from style_presets import apply_publication_style

# Apply publication style
apply_publication_style('default')
sns.set_theme(style='ticks', context='paper', font_scale=1.1)
sns.set_palette('colorblind')

# Create statistical comparison figure
fig, ax = plt.subplots(figsize=(3.5, 3))
# seaborn >=0.13: pass hue + legend=False to color by category
# (a bare palette= without hue= is deprecated, slated for removal in v0.14)
sns.boxplot(data=df, x='treatment', y='response',
            order=['Control', 'Low', 'High'],
            hue='treatment', palette='Set2', legend=False, 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()

# Save figure
from figure_export import save_publication_figure
save_publication_figure(fig, 'treatment_comparison', formats=['pdf', 'png'], dpi=300)

Core Principles and Best Practices

1. Resolution and File Format

Critical requirements (detailed in references/publication_guidelines.md):

Implementation:

# Use the figure_export.py script for correct settings
from figure_export import save_publication_figure

# Saves in multiple formats with proper DPI
save_publication_figure(fig, 'myfigure', formats=['pdf', 'png'], dpi=300)

# Or save for specific journal requirements
from figure_export import save_for_journal
save_for_journal(fig, 'figure1', journal='nature', figure_type='combination')

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):

# Option 1: Use assets/color_palettes.py
from color_palettes import OKABE_ITO_LIST, apply_palette
apply_palette('okabe_ito')

# Option 2: Manual specification
okabe_ito = ['#E69F00', '#56B4E9', '#009E73', '#F0E442',
             '#0072B2', '#D55E00', '#CC79A7', '#000000']
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=okabe_ito)

For heatmaps/continuous data:

Always test figures in grayscale to ensure interpretability.

3. Typography and Text

Font guidelines (detailed in references/publication_guidelines.md):

Implementation:

# Set fonts globally
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. Figure Dimensions

Journal-specific widths (detailed in references/journal_requirements.md):

Check figure size compliance:

from figure_export import check_figure_size

fig = plt.figure(figsize=(3.5, 3))  # 89 mm for Nature
check_figure_size(fig, journal='nature')

5. Multi-Panel Figures

Best practices:

Example implementation (see references/matplotlib_examples.md for complete code):

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 ...

# Add panel labels
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')

Common Tasks

Step-by-step recipes — full code for each lives in references/common_tasks.md and references/matplotlib_examples.md:

  1. Publication-ready line plot — style, journal size, colorblind colors, error bars, units, despine, vector export.
  2. Multi-panel figure — GridSpec layout, consistent styling, bold panel labels.
  3. Heatmap with proper colormap — perceptually uniform (viridis) or colorblind-safe diverging (RdBu_r), labeled colorbar, grayscale test.
  4. Prepare for a specific journal — configure_for_journal(...) then save_for_journal(...).
  5. Fix an existing figure — run the publication checklist (resolution, format, colors, fonts, labels, size, grayscale, chart junk).
  6. Colorblind-friendly figures — approved palettes + redundant encoding (line styles, markers) + simulator test.

Statistical rigor (always): error bars (SD/SEM/CI — state which in caption), sample size n, significance markers, individual data points where possible.

Plotting Libraries — when to use which

Resources

References Directory

Load these as needed for detailed information:

Scripts Directory

Use these helper scripts for automation:

Assets Directory

Use these files in figures:

Workflow Summary

Recommended workflow for creating publication figures:

  1. Plan: Determine target journal, figure type, and content
  2. Configure: Apply appropriate style for journal

```python

from style_presets import configure_for_journal

configure_for_journal('nature', 'single')

```

  1. Create: Build figure with proper labels, colors, statistics
  2. Verify: Check size, fonts, colors, accessibility

```python

from figure_export import check_figure_size

check_figure_size(fig, journal='nature')

```

  1. Export: Save in required formats

```python

from figure_export import save_for_journal

save_for_journal(fig, 'figure1', 'nature', 'combination')

```

  1. Review: View at final size in manuscript context

Common Pitfalls to Avoid

  1. Font too small: Text unreadable when printed at final size
  2. JPEG format: Never use JPEG for graphs/plots (creates artifacts)
  3. Red-green colors: ~8% of males cannot distinguish
  4. Low resolution: Pixelated figures in publication
  5. Missing units: Always label axes with units
  6. 3D effects: Distorts perception, avoid completely
  7. Chart junk: Remove unnecessary gridlines, decorations
  8. Truncated axes: Start bar charts at zero unless scientifically justified
  9. Inconsistent styling: Different fonts/colors across figures in same manuscript
  10. No error bars: Always show uncertainty

Final Checklist

Before submitting figures, verify:

Use this skill to ensure scientific figures meet the highest publication standards while remaining accessible to all readers.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.