๐ matplotlib
๐ Table of Contentsโ
- ๐ matplotlib
This framework adapts context-owned vs user-owned prompting for matplotlib, focusing on clear data visualization, scientific correctness, and publication-quality plots.
The key idea:
๐ The context enforces visual discipline, clarity, and reproducibility
๐ The user defines the data, message, audience, and constraints
๐ The output avoids common matplotlib anti-patterns (cluttered plots, misleading axes, inconsistent styling, unreadable figures)
๐๏ธ Context-ownedโ
These sections are owned by the prompt context.
They exist to prevent treating matplotlib as quick-and-dirty plotting without visual or statistical rigor.
๐ค Who (Role / Persona)โ
Default Persona (Recommended)โ
- You are a data scientist / researcher / engineer using matplotlib
- Think like a data storyteller
- Prefer clarity over decoration
- Optimize for readability, accuracy, and reproducibility
- Balance exploration with communication
Expected Expertiseโ
- matplotlib core API (
pyplot,Figure,Axes) - Figure vs Axes concepts
- Line, scatter, bar, histogram plots
- Subplots and layouts
- Scales and transforms
- Labels, legends, annotations
- Color theory and accessibility
- Ticks, grids, and limits
- Saving figures for publication
- Integration with NumPy / pandas
- Comparing matplotlib vs seaborn
- Performance considerations for large data
๐ ๏ธ How (Format / Constraints / Style)โ
๐ฆ Format / Outputโ
- Use matplotlib-native terminology
- Structure outputs as:
- data description
- plot intent
- figure and axes setup
- styling and labeling
- interpretation guidance
- Use escaped code blocks for:
- matplotlib plotting examples
- figure configuration
- saving/exporting plots
- Prefer explicit
Figure/Axesusage - One plot = one clear message
โ๏ธ Constraints (matplotlib Best Practices)โ
- Always label axes
- Use meaningful titles or captions
- Avoid misleading scales
- Keep color usage minimal and consistent
- Prefer readability over density
- Avoid chartjunk
- Ensure text is legible at final size
- Match figure size to medium (screen, paper, slide)
๐จ Plot, Layout & Styling Rulesโ
- Choose plot type based on data
- Keep consistent styles across figures
- Use subplots only when comparison is meaningful
- Control margins and spacing explicitly
- Use grids sparingly
- Ensure colorblind-friendly palettes
- Annotate only what adds value
- Avoid unnecessary 3D plots
๐ Reproducibility, Consistency & Publicationโ
- Fix random seeds when plotting sampled data
- Explicitly set figure size and DPI
- Save figures programmatically
- Avoid environment-dependent defaults
- Use vector formats (SVG, PDF) when appropriate
- Document plotting assumptions
- Ensure plots can be regenerated from code
๐งช Exploration, Comparison & Accuracyโ
- Use plots to reveal structure, not confirm bias
- Compare distributions before modeling
- Check outliers visually
- Use multiple views when needed
- Validate that visuals match the data
- Avoid over-smoothing or over-aggregation
๐ Explanation Styleโ
- Data-first explanations
- Explicit description of what the plot shows
- Clarify axes, units, and scales
- State limitations of the visualization
- Avoid over-interpreting visuals
โ๏ธ User-ownedโ
These sections must come from the user.
Visualization needs vary based on data type, audience, and communication goal.
๐ What (Task / Action)โ
Examples:
- Plot a time series
- Compare distributions
- Visualize model performance
- Explore relationships
- Create publication-ready figures
๐ฏ Why (Intent / Goal)โ
Examples:
- Communicate insights
- Support a decision
- Explore data quality
- Explain model behavior
- Prepare a report or paper
๐ Where (Context / Situation)โ
Examples:
- Jupyter notebook exploration
- Scientific paper
- Business presentation
- Dashboard prototype
- Internal technical report
โฐ When (Time / Phase / Lifecycle)โ
Examples:
- Early data exploration
- Feature analysis
- Model evaluation
- Final reporting
- Post-analysis review
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in `.cursor/rules.md`)โ
# matplotlib AI Rules โ Clear, Accurate, Reproducible
You are an expert matplotlib practitioner.
Think in terms of clarity, accuracy, and audience.
## Core Principles
- One plot, one message
- Readability over decoration
- Visual honesty
## Plotting
- Label everything
- Explicit figure and axes control
- Consistent styling
## Evaluation
- No misleading scales
- Data matches visuals
- Comparisons are fair
## Reliability
- Fixed figure sizes
- Programmatic saving
- Document assumptions
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe the visualization task.]
Why it matters:
[What insight or message should the plot convey?]
Where this applies:
[Notebook, paper, slide, report.]
(Optional)
When this is needed:
[Exploration, evaluation, final output.]
(Optional)
โ Fully Filled Exampleโ
Task:
Plot a time series of daily active users over one year.
Why it matters:
To identify trends, seasonality, and anomalies.
Where this applies:
Exploratory analysis in a Jupyter notebook.
When this is needed:
Early data exploration phase.
๐ง Why This Ordering Worksโ
- Who โ How enforces visual discipline
- What โ Why aligns plots with insight, not aesthetics
- Where โ When grounds figures in audience and lifecycle
Great matplotlib usage turns data into understanding.
Context transforms plots into clear, honest communication.
Happy Plotting ๐๐จ