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
In this repository264 other files it gives its agents.
- accessibility-a11ySkill
- alpine-jsSkill
- analytics-data-analysisSkill
- android-developmentSkill
- angular-developmentSkill
- angularSkill
- anime-jsSkill
- anthropic-claude-developmentSkill
- api-developmentSkill
- apollo-graphqlSkill
- aspnet-coreSkill
- astroSkill
- auth0-authenticationSkill
- autogen-developmentSkill
- automl-hyperparameter-optimizationSkill
- aws-developmentSkill
- azureSkill
- backend-developmentSkill
- bash-scriptingSkill
- beautifulsoup-parsingSkill
- bitbucket-workflowSkill
- blazorSkill
- blender-python-addonSkill
- blockchainSkill
- bootstrapSkill
- business-central-developmentSkill
- cheerio-parsingSkill
- chrome-extension-developmentSkill
- ci-cd-best-practicesSkill
- clean-architectureSkill
- clean-codeSkill
- clerk-authenticationSkill
- cloudflare-developmentSkill
- computer-vision-opencvSkill
- convexSkill
- cppSkill
- c-sharpSkill
- cssSkill
- cypressSkill
- data-analysis-jupyterSkill
- data-analystSkill
- data-jupyter-pythonSkill
- deep-learning-pythonSkill
- deep-learning-pytorchSkill
- deep-learningSkill
- deno-typescriptSkill
- design-systemsSkill
- devopsSkill
- django-pythonSkill
- django-rest-api-developmentSkill
- dockerSkill
- dotnetSkill
- drizzle-ormSkill
- drupal-developmentSkill
- elasticsearch-best-practicesSkill
- electron-developmentSkill
- elixirSkill
- embedded-stm32Skill
- esbuild-bundlerSkill
- ethereumSkill
- The first 60 shown.
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
- Distinctive: line 12
Write concise, technical Python code with accurate Matplotlib examples
- Distinctive: line 13
Create informative and visually appealing plots with proper labels, titles, and legends
- Distinctive: line 14
Use the object-oriented API for complex figures, pyplot for quick plots
- Distinctive: line 15
Follow PEP 8 style guidelines
- Distinctive: line 16
Consider color-blindness accessibility in all visualizations
- Very specific: line 22
Use fig, ax = plt.subplots() for explicit control
- Very specific: line 29
Use plt.plot(), plt.xlabel() for quick, interactive plots
- Very specific: line 31
Use %matplotlib inline in Jupyter notebooks
- Distinctive: line 46
Always include axis labels with units
- Distinctive: line 47
Use descriptive titles that convey the message
- Distinctive: line 48
Add legends when multiple series are present
- Very specific: line 49
Use annotations (ax.annotate()) to highlight key points
- Distinctive: line 54
Use colorblind-friendly palettes (e.g., 'viridis', 'plasma', 'cividis')
- Distinctive: line 55
Avoid red-green combinations for accessibility
- Distinctive: line 56
Use consistent colors for the same categories across figures
- Distinctive: line 57
Use appropriate colormaps for data type:
- Very specific: line 66
Use plt.subplots(nrows, ncols) for grid layouts
- Very specific: line 67
Use gridspec for complex, non-uniform layouts
- Very specific: line 69
Use constrained_layout=True or tight_layout() to prevent overlap
- Distinctive: line 74
Use appropriate DPI for intended output (72 screen, 300+ print)
- Very specific: line 81
Use built-in styles: plt.style.use('seaborn-v0_8'), 'ggplot'
- Distinctive: line 82
Create custom style files for consistent branding
- Very specific: line 87
Use LaTeX for mathematical notation: r'$\alpha = \frac{1}{2}$'
- Distinctive: line 95
Use vector formats (PDF, SVG, EPS) for publications
- Distinctive: line 96
Use PNG for web and presentations with transparency
- Distinctive: line 97
Use JPEG only for photographs (lossy compression)
- Very specific: line 101
Use bbox_inches='tight' to remove excess whitespace
- Very specific: line 104
Use transparent=True for overlays
- Very specific: line 108
Use rasterized=True for scatter plots with many points
- Distinctive: line 109
Consider downsampling data for visualization
- Very specific: line 111
Use plt.close('all') in loops creating many figures
- Distinctive: line 116
Use object-oriented API for production code
- Distinctive: line 117
Always label axes and include units
- Distinctive: line 118
Test visualizations at intended display size
- Distinctive: line 119
Consider accessibility in color choices
≈ “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.
Files
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 inlinein 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
gridspecfor complex, non-uniform layouts - Share axes with
sharex=True,sharey=Truefor comparison - Use
constrained_layout=Trueortight_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
facecolorfor background color - Specify
dpiappropriate for use case - Use
transparent=Truefor overlays
Performance Optimization
- Use
rasterized=Truefor 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
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
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.

