matplotlib-best-practices
Best practices for Matplotlib data visualization, plotting, and creating publication-quality figures in Python
What this skill does
# 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
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.