matplotlib/matplotlib · error · ValueError
z array must have same length as triangulation x and y array
Error message
z array must have same length as triangulation x and y arrays
What it means
Error "z array must have same length as triangulation x and y arrays" thrown in matplotlib/matplotlib.
Source
Thrown at lib/matplotlib/tri/_tricontour.py:59
self._mins = args[0]._mins
self._maxs = args[0]._maxs
else:
from matplotlib import _tri
tri, z = self._contour_args(args, kwargs)
C = _tri.TriContourGenerator(tri.get_cpp_triangulation(), z)
self._mins = [tri.x.min(), tri.y.min()]
self._maxs = [tri.x.max(), tri.y.max()]
self._contour_generator = C
return kwargs
def _contour_args(self, args, kwargs):
tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args,
**kwargs)
z, *args = args
z = np.ma.asarray(z)
if z.shape != tri.x.shape:
raise ValueError('z array must have same length as triangulation x'
' and y arrays')
# z values must be finite, only need to check points that are included
# in the triangulation.
z_check = z[np.unique(tri.get_masked_triangles())]
if np.ma.is_masked(z_check):
raise ValueError('z must not contain masked points within the '
'triangulation')
if not np.isfinite(z_check).all():
raise ValueError('z array must not contain non-finite values '
'within the triangulation')
z = np.ma.masked_invalid(z, copy=False)
self.zmax = float(z_check.max())
self.zmin = float(z_check.min())
if self.logscale and self.zmin <= 0:
func = 'contourf' if self.filled else 'contour'
raise ValueError(f'Cannot {func} log of negative values.')View on GitHub (pinned to b379c1b69e)
When it happens
Trigger: Thrown at lib/matplotlib/tri/_tricontour.py:59 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21).
Data as JSON: /api/errors/5f8e60afadadb8e2.
Report an issue: GitHub.