agentleFS
MindrallyMindrally/skills/matplotlib-best-practices/SKILL.md

matplotlib-best-practices

Skill266 starsChanged 10 months agoApache-2.0View on GitHub

Best practices for Matplotlib data visualization, plotting, and creating publication-quality figures in Python

The file

Show its rules and text

We split this skill into the rules it gives an agent

35 rules. About 0 are common, 22 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈22

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write concise, technical Python code with accurate Matplotlib examples

    line 12
  2. Distinctive:

    Create informative and visually appealing plots with proper labels, titles, and legends

    line 13
  3. Distinctive:

    Use the object-oriented API for complex figures, pyplot for quick plots

    line 14
  4. Distinctive:

    Follow PEP 8 style guidelines

    line 15
  5. Distinctive:

    Consider color-blindness accessibility in all visualizations

    line 16
  6. Very specific:

    Use fig, ax = plt.subplots() for explicit control

    line 22
  7. Very specific:

    Use plt.plot(), plt.xlabel() for quick, interactive plots

    line 29
  8. Very specific:

    Use %matplotlib inline in Jupyter notebooks

    line 31
  9. Distinctive:

    Always include axis labels with units

    line 46
  10. Distinctive:

    Use descriptive titles that convey the message

    line 47
  11. Distinctive:

    Add legends when multiple series are present

    line 48
  12. Very specific:

    Use annotations (ax.annotate()) to highlight key points

    line 49
  13. Distinctive:

    Use colorblind-friendly palettes (e.g., 'viridis', 'plasma', 'cividis')

    line 54
  14. Distinctive:

    Avoid red-green combinations for accessibility

    line 55
  15. Distinctive:

    Use consistent colors for the same categories across figures

    line 56
  16. Distinctive:

    Use appropriate colormaps for data type:

    line 57
  17. Very specific:

    Use plt.subplots(nrows, ncols) for grid layouts

    line 66
  18. Very specific:

    Use gridspec for complex, non-uniform layouts

    line 67
  19. Very specific:

    Use constrained_layout=True or tight_layout() to prevent overlap

    line 69
  20. Distinctive:

    Use appropriate DPI for intended output (72 screen, 300+ print)

    line 74
  21. Very specific:

    Use built-in styles: plt.style.use('seaborn-v0_8'), 'ggplot'

    line 81
  22. Distinctive:

    Create custom style files for consistent branding

    line 82
  23. Very specific:

    Use LaTeX for mathematical notation: r'$\alpha = \frac{1}{2}$'

    line 87
  24. Distinctive:

    Use vector formats (PDF, SVG, EPS) for publications

    line 95
  25. Distinctive:

    Use PNG for web and presentations with transparency

    line 96
  26. Distinctive:

    Use JPEG only for photographs (lossy compression)

    line 97
  27. Very specific:

    Use bbox_inches='tight' to remove excess whitespace

    line 101
  28. Very specific:

    Use transparent=True for overlays

    line 104
  29. Very specific:

    Use rasterized=True for scatter plots with many points

    line 108
  30. Distinctive:

    Consider downsampling data for visualization

    line 109
  31. Very specific:

    Use plt.close('all') in loops creating many figures

    line 111
  32. Distinctive:

    Use object-oriented API for production code

    line 116
  33. Distinctive:

    Always label axes and include units

    line 117
  34. Distinctive:

    Test visualizations at intended display size

    line 118
  35. Distinctive:

    Consider accessibility in color choices

    line 119

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Matplotlib Best Practices

Expert guidelines for Matplotlib development, focusing on data visualization, plotting, and creating publication-quality figures.

Code Style and Structure

  • Write concise, technical Python code with accurate Matplotlib examples
  • Create informative and visually appealing plots with proper labels, titles, and legends
  • Use the object-oriented API for complex figures, pyplot for quick plots
  • Follow PEP 8 style guidelines
  • Consider color-blindness accessibility in all visualizations

API Approaches

Object-Oriented Interface (Recommended)

  • Use fig, ax = plt.subplots() for explicit control
  • Preferred for complex figures and production code
  • Methods are called on axes objects: ax.plot(), ax.set_xlabel()
  • Enables multiple subplots and fine-grained customization

Pyplot Interface

  • Use plt.plot(), plt.xlabel() for quick, interactive plots
  • Suitable for Jupyter notebooks and exploration
  • Use %matplotlib inline in Jupyter notebooks

Creating Effective Visualizations

Plot Types and Selection

  • Line plots (ax.plot()) for continuous data and trends
  • Scatter plots (ax.scatter()) for relationship between variables
  • Bar plots (ax.bar(), ax.barh()) for categorical comparisons
  • Histograms (ax.hist()) for distributions
  • Box plots (ax.boxplot()) for statistical summaries
  • Heatmaps (ax.imshow(), ax.pcolormesh()) for 2D data

Labels and Annotations

  • Always include axis labels with units
  • Use descriptive titles that convey the message
  • Add legends when multiple series are present
  • Use annotations (ax.annotate()) to highlight key points
  • Include data source attribution when appropriate

Color and Style

  • Use colorblind-friendly palettes (e.g., 'viridis', 'plasma', 'cividis')
  • Avoid red-green combinations for accessibility
  • Use consistent colors for the same categories across figures
  • Use appropriate colormaps for data type:
    • Sequential: 'viridis', 'plasma' for continuous data
    • Diverging: 'RdBu', 'coolwarm' for data with meaningful center
    • Qualitative: 'Set1', 'tab10' for categorical data

Figure Layout and Composition

Subplots

  • Use plt.subplots(nrows, ncols) for grid layouts
  • Use gridspec for complex, non-uniform layouts
  • Share axes with sharex=True, sharey=True for comparison
  • Use constrained_layout=True or tight_layout() to prevent overlap

Figure Size and Resolution

  • Set figure size explicitly: figsize=(width, height) in inches
  • Use appropriate DPI for intended output (72 screen, 300+ print)
  • Standard sizes: (10, 6) for presentations, (8, 6) for papers

Customization

Style Sheets

  • Use built-in styles: plt.style.use('seaborn-v0_8'), 'ggplot'
  • Create custom style files for consistent branding
  • Combine styles: plt.style.use(['seaborn-v0_8', 'custom.mplstyle'])

Text and Fonts

  • Use LaTeX for mathematical notation: r'$\alpha = \frac{1}{2}$'
  • Set font family for consistency
  • Adjust font sizes for readability at intended display size

Saving and Exporting

File Formats

  • Use vector formats (PDF, SVG, EPS) for publications
  • Use PNG for web and presentations with transparency
  • Use JPEG only for photographs (lossy compression)

Export Settings

  • Use bbox_inches='tight' to remove excess whitespace
  • Set facecolor for background color
  • Specify dpi appropriate for use case
  • Use transparent=True for overlays

Performance Optimization

  • Use rasterized=True for scatter plots with many points
  • Consider downsampling data for visualization
  • Close figures with plt.close() after saving
  • Use plt.close('all') in loops creating many figures

Key Conventions

  • Import as import matplotlib.pyplot as plt
  • Use object-oriented API for production code
  • Always label axes and include units
  • Test visualizations at intended display size
  • Consider accessibility in color choices

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.