Title: [Bug]: macosx backend, plots not closing, segfault · Issue #32019 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: macosx backend, plots not closing, segfault · Issue #32019 · matplotlib/matplotlib
X Title: [Bug]: macosx backend, plots not closing, segfault · Issue #32019 · matplotlib/matplotlib
Description: Bug summary I am trying to create a plot in a for-loop. I can move each plot around, but even if I close it (click the ❌, use plt.close()), all prior plots are still displayed behind the newest plot. If I try to close plots (click the ❌)...
Open Graph Description: Bug summary I am trying to create a plot in a for-loop. I can move each plot around, but even if I close it (click the ❌, use plt.close()), all prior plots are still displayed behind the newest plo...
X Description: Bug summary I am trying to create a plot in a for-loop. I can move each plot around, but even if I close it (click the ❌, use plt.close()), all prior plots are still displayed behind the newest plo...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32019
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: macosx backend, plots not closing, segfault","articleBody":"### Bug summary\n\nI am trying to create a plot in a for-loop. I can move each plot around, but even if I close it (click the ❌, use `plt.close()`), all prior plots are still displayed behind the newest plot. If I try to close plots (click the ❌) out of order, it results in a segfault.\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfor _ in range(100):\n fig, ax = plt.subplots()\n x = np.random.rand(10)\n y = np.random.rand(10)\n ax.plot(x, y)\n plt.show()\n plt.close()\n```\n\n### Actual outcome\n\n```\n\u003e python3 -X faulthandler test.py\nFatal Python error: Segmentation fault\n\nCurrent thread 0x00000001f5cc1e80 (most recent call first):\n File \"/Users/Adam/torchgeo/.venv/lib/python3.14/site-packages/matplotlib/backends/backend_macosx.py\", line 180 in start_main_loop\n File \"/Users/Adam/torchgeo/.venv/lib/python3.14/site-packages/matplotlib/backend_bases.py\", line 3702 in show\n File \"/Users/Adam/torchgeo/.venv/lib/python3.14/site-packages/matplotlib/pyplot.py\", line 646 in show\n File \"/Users/Adam/Downloads/test.py\", line 9 in \u003cmodule\u003e\n\nCurrent thread's C stack trace (most recent call first):\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _Py_DumpStack+0x44 [0x101cf10a4]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at faulthandler_dump_c_stack+0x54 [0x101d68f48]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at faulthandler_fatal_error+0x16c [0x101d68df8]\n Binary file \"/usr/lib/system/libsystem_platform.dylib\", at _sigtramp+0x38 [0x189b4b744]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _Py_Dealloc+0x38 [0x1013b0238]\n Binary file \"/Users/Adam/torchgeo/.venv/lib/python3.14/site-packages/matplotlib/backends/_macosx.cpython-314-darwin.so\", at -[Window close]+0x7c [0x106c59f70]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSWindow __close]+0x178 [0x18e2e2ad8]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSApplication(NSResponder) sendAction:to:from:]+0x230 [0x18e1c66c0]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSControl sendAction:to:]+0x48 [0x18e1c6460]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at __26-[NSCell _sendActionFrom:]_block_invoke+0x64 [0x18e1c63a4]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSCell _sendActionFrom:]+0xcc [0x18e1c62cc]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSButtonCell _sendActionFrom:]+0x60 [0x18e1c61c8]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at NSControlTrackMouse+0x5d4 [0x18e1c37b0]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSCell trackMouse:inRect:ofView:untilMouseUp:]+0x90 [0x18e1c31b0]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:]+0xe4 [0x18e1c307c]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSControl(_NSTracking) _mouseDown:]+0x260 [0x18e712a74]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSControl(_NSTracking) mouseDown:]+0x68 [0x18e7127e8]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]+0xe70 [0x18e1c1c04]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]+0x1ec [0x18e1501f4]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSWindow(NSEventRouting) sendEvent:]+0x17c [0x18e14fe64]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSApplication(NSEventRouting) sendEvent:]+0x4fc [0x18ebc040c]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSApplication _handleEvent:]+0x3c [0x18e80d664]\n Binary file \"/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit\", at -[NSApplication run]+0x198 [0x18e01f164]\n Binary file \"/Users/Adam/torchgeo/.venv/lib/python3.14/site-packages/matplotlib/backends/_macosx.cpython-314-darwin.so\", at show+0x74 [0x106c5e970]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _TAIL_CALL_CALL_NON_PY_GENERAL.llvm.10127954890374434623+0x104 [0x101705924]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _PyFunction_Vectorcall+0x338 [0x10167429c]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at method_vectorcall.llvm.1628862021063799139+0x94 [0x1016b7330]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _TAIL_CALL_CALL_FUNCTION_EX.llvm.10127954890374434623+0x10c [0x101469578]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at _PyEval_Vector+0x30c [0x1014f5d00]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at PyEval_EvalCode+0xa0 [0x10150588c]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at run_mod.llvm.9148091775861049191+0x124 [0x101517a7c]\n Binary file \"/Users/Adam/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/libpython3.14.dylib\", at pyrun_file+0xa4 [0x101645880]\n \u003ctruncated rest of calls\u003e\n\nExtension modules: numpy._core._multiarray_umath, numpy.linalg._umath_linalg, PIL._imaging, kiwisolver._cext, matplotlib.backends._macosx, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._pcg64, numpy.random._generator, numpy.random._mt19937, numpy.random._philox, numpy.random._sfc64, numpy.random.mtrand (total: 14)\nfish: Job 1, 'python3 -X faulthandler test.py' terminated by signal SIGSEGV (Address boundary error)\n```\n\n### Expected outcome\n\nI would expect no phantom plots and no segfaults.\n\n### Additional information\n\nTried Python 3.13 and 3.14 in fresh uv environments, no luck so far. Happy to try other debugging suggestions.\n\n### Operating system\n\nmacOS Tahoe 26.5.1\n\n### Matplotlib Version\n\n3.11.0\n\n### Matplotlib Backend\n\nmacosx\n\n### Python version\n\n3.14.4\n\n### Jupyter version\n\nN/A\n\n### Installation\n\nuv","author":{"url":"https://github.com/adamjstewart","@type":"Person","name":"adamjstewart"},"datePublished":"2026-07-08T20:22:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":18},"url":"https://github.com/32019/matplotlib/issues/32019"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cffbf135-730e-9400-69be-f5b7fa2fd31c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D2E0:18AAA8:1B0C5C2:2504F1B:6A540124 |
| html-safe-nonce | c324fe47c826817e01e44b717e50dbbe3f6c5e3232a9230abb8edc63d9398bc6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkUwOjE4QUFBODoxQjBDNUMyOjI1MDRGMUI6NkE1NDAxMjQiLCJ2aXNpdG9yX2lkIjoiNzkxODc4NzkwNzMwMDg4NDc3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2957d68c05464d0a99f43b55024dd0f34969d097a6cec119d105a9c8902542ad |
| hovercard-subject-tag | issue:4840828925 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32019/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c86b85e0329f5dac51deb930cbcddcfefdad88567afc6cb0f69ca5ea5b7a7cc4/matplotlib/matplotlib/issues/32019 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c86b85e0329f5dac51deb930cbcddcfefdad88567afc6cb0f69ca5ea5b7a7cc4/matplotlib/matplotlib/issues/32019 |
| og:image:alt | Bug summary I am trying to create a plot in a for-loop. I can move each plot around, but even if I close it (click the ❌, use plt.close()), all prior plots are still displayed behind the newest plo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adamjstewart |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width