Skip to main content

๐Ÿ“ˆ matplotlib

๐Ÿ“š Table of Contentsโ€‹

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)โ€‹

  • 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 / Axes usage
  • 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

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 ๐Ÿ“ˆ๐ŸŽจ