{"record":{"id":"f0c093a2c94b748c","repo":"matplotlib/matplotlib","slug":"image-sizes-do-not-match-expected-size-expected","errorCode":null,"errorMessage":"Image sizes do not match expected size: {expected_image.shape} actual size {actual_image.shape}","messagePattern":"Image sizes do not match expected size: (.+?) actual size (.+?)","errorType":"exception","errorClass":"ImageComparisonFailure","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/testing/compare.py","lineNumber":391,"sourceCode":"\n\ndef crop_to_same(actual_path, actual_image, expected_path, expected_image):\n    # clip the images to the same size -- this is useful only when\n    # comparing eps to pdf\n    if actual_path[-7:-4] == 'eps' and expected_path[-7:-4] == 'pdf':\n        aw, ah, ad = actual_image.shape\n        ew, eh, ed = expected_image.shape\n        actual_image = actual_image[int(aw / 2 - ew / 2):int(\n            aw / 2 + ew / 2), int(ah / 2 - eh / 2):int(ah / 2 + eh / 2)]\n    return actual_image, expected_image\n\n\ndef calculate_rms(expected_image, actual_image):\n    \"\"\"\n    Calculate the per-pixel errors, then compute the root mean square error.\n    \"\"\"\n    if expected_image.shape != actual_image.shape:\n        raise ImageComparisonFailure(\n            f\"Image sizes do not match expected size: {expected_image.shape} \"\n            f\"actual size {actual_image.shape}\")\n    # Convert to float to avoid overflowing finite integer types.\n    return np.sqrt(((expected_image - actual_image).astype(float) ** 2).mean())\n\n\n# NOTE: compare_image and save_diff_image assume that the image does not have\n# 16-bit depth, as Pillow converts these to RGB incorrectly.\n\n\ndef _load_image(path):\n    img = Image.open(path)\n    if img.mode != \"RGB\":\n        # If we have anything other than RGB(A) (e.g., a paletted image), convert it\n        # to RGBA.\n        if img.mode != \"RGBA\":\n            img = img.convert(\"RGBA\")\n        # In an RGBA image, if the smallest value in the alpha channel is 255, all","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/testing/compare.py#L373-L409","documentation":"Error \"Image sizes do not match expected size: {expected_image.shape} actual size {actual_image.shape}\" thrown in matplotlib/matplotlib.","triggerScenarios":"Thrown at lib/matplotlib/testing/compare.py:391 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}