Hidden Assumptions in matplotlib
10 assumptions this code never checks · 4 critical · spanning Domain, Scale, Resource, Shape, Ordering
Every codebase relies on things it never checks. Most of them are routine. CodeSea looked at matplotlib/matplotlib and picked out the few most likely to cause trouble. The full list is just below.
Most of what this code assumes is routine. These 3 are the ones most likely to cause trouble here. The rest are minor; they're under "Show everything".
Invalid angle inputs (like extremely large values or NaN) could cause infinite loops in arc tessellation or produce garbage geometry that renders as visual artifacts
Highly curved or degenerate bezier curves could exceed recursion limit and produce incomplete or incorrect curve tessellation, causing missing plot elements
Large filter radius values could allocate gigabytes of memory for lookup tables, causing out-of-memory errors or system instability
Show everything (7 more)
Curve approximation epsilons (1e-30) are appropriate for all coordinate scales from microscopic to astronomical data
If this fails: Plots with very large coordinate values (like astronomical data) or very small values (like molecular simulations) could have curves that fail to tessellate properly or consume excessive memory
extern/agg24-svn/src/agg_curves.cpp:curve_distance_epsilon
B-spline control point arrays (m_x, m_y) remain valid pointers throughout the spline's lifetime
If this fails: If the arrays passed to bspline are deallocated or reallocated elsewhere, the spline object accesses freed memory causing crashes or corruption
extern/agg24-svn/src/agg_bspline.cpp:bspline
Line width values are in the same coordinate system as the smoothing width and both represent pixel-based measurements
If this fails: Mixing coordinate systems (data coordinates vs pixel coordinates) in line width calculations produces lines that are either invisibly thin or massively thick
extern/agg24-svn/src/agg_line_profile_aa.cpp:width
Rectangle coordinates x1,y1 represent bottom-left and x2,y2 represent top-right, with automatic coordinate swapping handling all cases
If this fails: Code that depends on specific corner semantics after construction could access wrong corners, leading to incorrect clipping or rendering bounds
extern/agg24-svn/src/agg_rounded_rect.cpp:rect
The embedded GSV font data has a specific binary format with fixed header structure and glyph encoding
If this fails: If font data gets corrupted or the format assumptions change, text rendering fails silently or produces garbage characters
extern/agg24-svn/src/agg_gsv_text.cpp:gsv_default_font
Arrowhead dimensions (m_head_d1, m_head_d2, etc.) are in the same units as the path coordinates they will be applied to
If this fails: Unit mismatches cause arrows that are either invisible (too small) or dominate the plot (too large), making line plots unreadable
extern/agg24-svn/src/agg_arrowhead.cpp:arrowhead
Embedded font bitmap data fits in available memory and character codes map correctly to glyph indices
If this fails: Invalid character codes or corrupted bitmap data causes buffer overruns or displays wrong characters in plot labels and titles
extern/agg24-svn/src/agg_embedded_raster_fonts.cpp:gse4x6
See the full structural analysis of matplotlib: the pipeline, data models, and system behavior that put these assumptions in context.
Full analysis of matplotlib/matplotlib →Frequently Asked Questions
What does matplotlib assume that could break in production?
The one most likely to cause trouble: Arc angles are in radians and sweep angle differences are mathematically valid (no NaN/inf values from floating point operations) If this fails, Invalid angle inputs (like extremely large values or NaN) could cause infinite loops in arc tessellation or produce garbage geometry that renders as visual artifacts
How many hidden assumptions does matplotlib have?
CodeSea found 10 assumptions matplotlib relies on but never validates, 4 of them critical, spanning Domain, Scale, Resource, Shape, Ordering. Most are routine — the analysis flags the two or three most likely to actually bite.
What is a hidden assumption?
Something the code depends on but never checks: a data shape, an ordering, an environment condition, a scale limit, or a contract with another service. It holds until the world it runs in changes, then fails silently.