{"record":{"id":"cd5b9637b6c8740c","repo":"matplotlib/matplotlib","slug":"the-shapes-of-the-passed-in-arrays-do-not-match","errorCode":null,"errorMessage":"The shapes of the passed in arrays do not match","messagePattern":"The shapes of the passed in arrays do not match","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/quiver.py","lineNumber":496,"sourceCode":"    if X is not None:\n        X = X.ravel()\n        Y = Y.ravel()\n        if len(X) == nc and len(Y) == nr:\n            X, Y = (a.ravel() for a in np.meshgrid(X, Y))\n        elif len(X) != len(Y):\n            raise ValueError('X and Y must be the same size, but '\n                             f'X.size is {X.size} and Y.size is {Y.size}.')\n    else:\n        indexgrid = np.meshgrid(np.arange(nc), np.arange(nr))\n        X, Y = (np.ravel(a) for a in indexgrid)\n    # Size validation for U, V, C is left to the set_UVC method.\n    return X, Y, U, V, C\n\n\ndef _check_consistent_shapes(*arrays):\n    all_shapes = {a.shape for a in arrays}\n    if len(all_shapes) != 1:\n        raise ValueError('The shapes of the passed in arrays do not match')\n\n\nclass Quiver(mcollections.PolyCollection):\n    \"\"\"\n    Specialized PolyCollection for arrows.\n\n    Use set_UVC to change the size, orientation, and color of the\n    arrows; their locations can be set using set_offsets().\n\n    Much of the work in this class is done in the draw()\n    method so that as much information as possible is available\n    about the plot.  In subsequent draw() calls, recalculation\n    is limited to things that might have changed, so there\n    should be no performance penalty from putting the calculations\n    in the draw() method.\n    \"\"\"\n\n    _PIVOT_VALS = ('tail', 'middle', 'tip')","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/quiver.py#L478-L514","documentation":"_check_consistent_shapes is Barbs' internal gate (called from Barbs.set_UVC and Barbs.set_offsets after cbook.delete_masked_points). It collects {a.shape for a in arrays} and raises ValueError('The shapes of the passed in arrays do not match') when positions (x, y), components (u, v), colors (c) and flip flags do not all end up identically shaped after masked points are dropped.","triggerScenarios":"plt.barbs(x, y, u, v, c) where c has a different number of points than x/y/u/v; using masked arrays whose masks differ across inputs so delete_masked_points removes different counts; barb.set_offsets(xy) with more or fewer positions than the stored u/v data.","commonSituations":"Wind-barb plots where the color array came from a differently-sized source (e.g., station metadata subset); updating barb offsets with a new station list while keeping old u/v; NaN patterns that differ between u, v, and c fields.","solutions":["Make all inputs describe the same number of barbs: assert len(x) == len(y) == len(u) == len(v) (and len(c) if given)","Apply the same NaN mask across fields: mask = np.isnan(u) | np.isnan(v); x, y, u, v, c = (a[~mask] for a in (x, y, u, v, c))","When positions change, rebuild the Barbs artist instead of calling set_offsets with a different count"],"exampleFix":"# before\nplt.barbs(x, y, u, v, c)  # c has 100 points, u/v have 120 -> ValueError\n\n# after\nkeep = ~np.isnan(u) & ~np.isnan(v)\nplt.barbs(x[keep], y[keep], u[keep], v[keep], c[keep])","handlingStrategy":"validation","validationCode":"import numpy as np\nkeep = ~np.isnan(u) & ~np.isnan(v) & ~np.isnan(c)\nx, y, u, v, c = (np.asarray(a)[keep] for a in (x, y, u, v, c))\nsizes = {a.size for a in (x, y, u, v, c)}\nassert len(sizes) == 1, f'arrays describe different barb counts: {sizes}'\nplt.barbs(x, y, u, v, c)","typeGuard":null,"tryCatchPattern":"try:\n    plt.barbs(x, y, u, v, c)\nexcept ValueError as e:\n    if 'shapes of the passed in arrays' in str(e):\n        n = min(len(x), len(y), len(u), len(v), len(c))\n        plt.barbs(x[:n], y[:n], u[:n], v[:n], c[:n])\n    else:\n        raise","preventionTips":["Pass the same number of positions, components, and colors to barbs","Apply one shared mask across all fields so delete_masked_points removes the same rows","When the station list changes, rebuild the Barbs artist rather than reusing set_offsets"],"tags":["matplotlib","barbs","quiver","shape-mismatch","masked-arrays","numpy-arrays"],"backgroundTag":"array-shape-mismatch","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}