Skip to main content
Matplotlib-specific code generation requirements. This module validates Python code that uses matplotlib for plotting, ensuring proper headless backend configuration, file I/O, and dependency availability.

Classes

CLASS MatplotlibHeadlessBackend

Validates that matplotlib is configured with a headless backend. Matplotlib must be explicitly configured with a headless backend (e.g., ‘Agg’) via matplotlib.use() before importing pyplot. Interactive backends like ‘TkAgg’ will fail because they require a display server.

CLASS PlotFileSaved

Validates that a plot is explicitly saved to a file. The plot must be saved using savefig() with the specified output_path. This prevents interactive plot displays (plt.show()) and ensures output can be captured and verified. Args:
  • output_path: File path where the plot should be saved (e.g., ‘/tmp/plot.png’).

CLASS PlotDependenciesAvailable

Validates that matplotlib and numpy are importable. Both matplotlib and numpy must be available in the execution environment. This requirement checks import availability but does not execute code.