René's URL Explorer Experiment


Title: [Bug]: Crash when removing colorbar axes in a constrained layout · Issue #31330 · matplotlib/matplotlib · GitHub

Open Graph Title: [Bug]: Crash when removing colorbar axes in a constrained layout · Issue #31330 · matplotlib/matplotlib

X Title: [Bug]: Crash when removing colorbar axes in a constrained layout · Issue #31330 · matplotlib/matplotlib

Description: Bug summary The program crashes if we remove the axes of the colorbar cbar by calling cbar.ax.remove() in a figure with constrained layout. The crash does not occur if we do not specify a constrained layout. Code for reproduction import ...

Open Graph Description: Bug summary The program crashes if we remove the axes of the colorbar cbar by calling cbar.ax.remove() in a figure with constrained layout. The crash does not occur if we do not specify a constrain...

X Description: Bug summary The program crashes if we remove the axes of the colorbar cbar by calling cbar.ax.remove() in a figure with constrained layout. The crash does not occur if we do not specify a constrain...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31330

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Crash when removing colorbar axes in a constrained layout","articleBody":"### Bug summary\n\nThe program crashes if we remove the axes of the colorbar `cbar` by calling `cbar.ax.remove()` in a figure with constrained layout. The crash does not occur if we do not specify a constrained layout.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nimport numpy as np\n\ndelta = 0.025\nx = y = np.arange(-3.0, 3.01, delta)\nX, Y = np.meshgrid(x, y)\nZ1 = np.exp(-X**2 - Y**2)\nZ2 = np.exp(-(X - 1)**2 - (Y - 1)**2)\nZ = (Z1 - Z2) * 2\n\nfig, ax = plt.subplots(layout='constrained')\nCS = ax.contourf(X, Y, Z, 10, cmap=\"bone\")\ncbar = fig.colorbar(CS)\ncbar.ax.remove()\nplt.show()\n```\n\n### Actual outcome\n\n---------------------------------------------------------------------------\nAttributeError                            Traceback (most recent call last)\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/backend_bases.py:1152, in TimerBase._on_timer(self)\n   1146 \"\"\"\n   1147 Runs all function that have been registered as callbacks. Functions\n   1148 can return False (or 0) if they should not be called any more. If there\n   1149 are no callbacks, the timer is automatically stopped.\n   1150 \"\"\"\n   1151 for func, args, kwargs in self.callbacks:\n-\u003e 1152     ret = func(*args, **kwargs)\n   1153     # docstring above explains why we use `if ret == 0` here,\n   1154     # instead of `if not ret`.\n   1155     # This will also catch `ret == False` as `False == 0`\n   1156     # but does not annoy the linters\n   1157     # https://docs.python.org/3/library/stdtypes.html#boolean-values\n   1158     if ret == 0:\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py:71, in FigureCanvasMac._single_shot_timer.\u003clocals\u003e.callback_func(callback, timer)\n     70 def callback_func(callback, timer):\n---\u003e 71     callback()\n     72     self._timers.remove(timer)\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py:93, in FigureCanvasMac._draw_idle(self)\n     91     return\n     92 self._draw_pending = False\n---\u003e 93 self.draw()\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py:56, in FigureCanvasMac.draw(self)\n     54     return\n     55 with cbook._setattr_cm(self, _is_drawing=True):\n---\u003e 56     super().draw()\n     57 self.update()\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py:382, in FigureCanvasAgg.draw(self)\n    379 # Acquire a lock on the shared font cache.\n    380 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar\n    381       else nullcontext()):\n--\u003e 382     self.figure.draw(self.renderer)\n    383     # A GUI class may be need to update a window using this draw, so\n    384     # don't forget to call the superclass.\n    385     super().draw()\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/artist.py:94, in _finalize_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer, *args, **kwargs)\n     92 @wraps(draw)\n     93 def draw_wrapper(artist, renderer, *args, **kwargs):\n---\u003e 94     result = draw(artist, renderer, *args, **kwargs)\n     95     if renderer._rasterizing:\n     96         renderer.stop_rasterizing()\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/artist.py:71, in allow_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer)\n     68     if artist.get_agg_filter() is not None:\n     69         renderer.start_filter()\n---\u003e 71     return draw(artist, renderer)\n     72 finally:\n     73     if artist.get_agg_filter() is not None:\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/figure.py:3251, in Figure.draw(self, renderer)\n   3249 if self.axes and self.get_layout_engine() is not None:\n   3250     try:\n-\u003e 3251         self.get_layout_engine().execute(self)\n   3252     except ValueError:\n   3253         pass\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/layout_engine.py:278, in ConstrainedLayoutEngine.execute(self, fig)\n    275 w_pad = self._params['w_pad'] / width\n    276 h_pad = self._params['h_pad'] / height\n--\u003e 278 return do_constrained_layout(fig, w_pad=w_pad, h_pad=h_pad,\n    279                              wspace=self._params['wspace'],\n    280                              hspace=self._params['hspace'],\n    281                              rect=self._params['rect'],\n    282                              compress=self._compress)\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/_constrained_layout.py:116, in do_constrained_layout(fig, h_pad, w_pad, hspace, wspace, rect, compress)\n    106     return\n    108 for _ in range(2):\n    109     # do the algorithm twice.  This has to be done because decorations\n    110     # change size after the first re-position (i.e. x/yticklabels get\n   (...)\n    114     # make margins for all the Axes and subfigures in the\n    115     # figure.  Add margins for colorbars...\n--\u003e 116     make_layout_margins(layoutgrids, fig, renderer, h_pad=h_pad,\n    117                         w_pad=w_pad, hspace=hspace, wspace=wspace)\n    118     make_margin_suptitles(layoutgrids, fig, renderer, h_pad=h_pad,\n    119                           w_pad=w_pad)\n    121     # if a layout is such that a columns (or rows) margin has no\n    122     # constraints, we need to make all such instances in the grid\n    123     # match in margin size.\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/_constrained_layout.py:405, in make_layout_margins(layoutgrids, fig, renderer, w_pad, h_pad, hspace, wspace)\n    403 cbp_rspan, cbp_cspan = get_cb_parent_spans(cbax)\n    404 loc = cbax._colorbar_info['location']\n--\u003e 405 cbpos, cbbbox = get_pos_and_bbox(cbax, renderer)\n    406 if loc == 'right':\n    407     if cbp_cspan.stop == ss.colspan.stop:\n    408         # only increase if the colorbar is on the right edge\n\nFile ~/anaconda3/lib/python3.11/site-packages/matplotlib/_constrained_layout.py:644, in get_pos_and_bbox(ax, renderer)\n    642 pos = ax.get_position(original=True)\n    643 # pos is in panel co-ords, but we need in figure for the layout\n--\u003e 644 pos = pos.transformed(fig.transSubfigure - fig.transFigure)\n    645 tightbbox = martist._get_tightbbox_for_layout_only(ax, renderer)\n    646 if tightbbox is None:\n\nAttributeError: 'NoneType' object has no attribute 'transSubfigure'\n\n\n### Expected outcome\n\nA plot without the colorbar is displayed without errors.\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n0.2.0.dev53882+unknown.g607d2c380.g02b42db27\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/williamlus","@type":"Person","name":"williamlus"},"datePublished":"2026-03-19T04:44:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/31330/matplotlib/issues/31330"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0c82ba86-2e36-99d7-e868-6366d2e72105
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD67E:26C765:5A9E5A:7AB234:6A52394A
html-safe-noncebdeeaedff60788f49600af45aa9c5215cfe997ad339a60447454ba00dbc3fefe
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjdFOjI2Qzc2NTo1QTlFNUE6N0FCMjM0OjZBNTIzOTRBIiwidmlzaXRvcl9pZCI6IjYwODY2MDUwNjE1NzM5ODM0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacbe62f01734526eef7eb623c1ac4097540226ddb249c1d468aec2c36a74beffbe
hovercard-subject-tagissue:4099260039
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/31330/issue_layout
twitter:imagehttps://opengraph.githubassets.com/178615561cc9bf0900a905d2a5aa337ef0122dfeee3996fc1fcdf8cbf12027bf/matplotlib/matplotlib/issues/31330
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/178615561cc9bf0900a905d2a5aa337ef0122dfeee3996fc1fcdf8cbf12027bf/matplotlib/matplotlib/issues/31330
og:image:altBug summary The program crashes if we remove the axes of the colorbar cbar by calling cbar.ax.remove() in a figure with constrained layout. The crash does not occur if we do not specify a constrain...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamewilliamlus
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/31330#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F31330
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F31330
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/31330
Reloadhttps://github.com/matplotlib/matplotlib/issues/31330
Reloadhttps://github.com/matplotlib/matplotlib/issues/31330
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/31330
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/31330
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#31555https://github.com/matplotlib/matplotlib/pull/31555
[Bug]: Crash when removing colorbar axes in a constrained layouthttps://github.com/matplotlib/matplotlib/issues/31330#top
#31555https://github.com/matplotlib/matplotlib/pull/31555
v3.11.0https://github.com/matplotlib/matplotlib/milestone/96
https://github.com/williamlus
williamlushttps://github.com/williamlus
on Mar 19, 2026https://github.com/matplotlib/matplotlib/issues/31330#issue-4099260039
https://docs.python.org/3/library/stdtypes.html#boolean-valueshttps://docs.python.org/3/library/stdtypes.html#boolean-values
@wrapshttps://github.com/wraps
v3.11.0https://github.com/matplotlib/matplotlib/milestone/96
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.