René's URL Explorer Experiment


Title: [Bug]: Intermittent `ValueError: The passed figure is not managed by pyplot` with ipympl (`%matplotlib widget`) · Issue #622 · matplotlib/ipympl · GitHub

Open Graph Title: [Bug]: Intermittent `ValueError: The passed figure is not managed by pyplot` with ipympl (`%matplotlib widget`) · Issue #622 · matplotlib/ipympl

X Title: [Bug]: Intermittent `ValueError: The passed figure is not managed by pyplot` with ipympl (`%matplotlib widget`) · Issue #622 · matplotlib/ipympl

Description: Bug summary When using Matplotlib with ipympl (%matplotlib widget) in JupyterLab, I intermittently get: ValueError: The passed figure is not managed by pyplot This happens with standard pyplot usage (plt.figure, plt.subplots(num=fig), pl...

Open Graph Description: Bug summary When using Matplotlib with ipympl (%matplotlib widget) in JupyterLab, I intermittently get: ValueError: The passed figure is not managed by pyplot This happens with standard pyplot usag...

X Description: Bug summary When using Matplotlib with ipympl (%matplotlib widget) in JupyterLab, I intermittently get: ValueError: The passed figure is not managed by pyplot This happens with standard pyplot usag...

Opengraph URL: https://github.com/matplotlib/ipympl/issues/622

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Intermittent `ValueError: The passed figure is not managed by pyplot` with ipympl (`%matplotlib widget`)","articleBody":"### Bug summary\n\nWhen using Matplotlib with ipympl (`%matplotlib widget`) in JupyterLab, I intermittently get:\n\n```\nValueError: The passed figure is not managed by pyplot\n```\n\nThis happens with standard pyplot usage (`plt.figure`, `plt.subplots(num=fig)`, `plt.sca(ax)`), without explicitly constructing canvases.\n\n### Code for reproduction\n\n```Python\n%matplotlib widget\nimport time\nimport matplotlib.pyplot as plt\n\ndef try_once():\n    fig_num = 1\n    plt.close(fig_num)\n    fig = plt.figure(fig_num)\n\n    fig, axs = plt.subplots(10, 10, num=fig, squeeze=False)\n\n    for ax in axs.flat:\n        plt.sca(ax)  # \u003c-- intermittently raises\n        plt.plot([1, 2, 3])\n        fig.canvas.draw_idle()\n        time.sleep(0.001)\n\nfor i in range(300):\n    try:\n        try_once()\n    except Exception as e:\n        print('FAILED at iteration', i, '-\u003e', repr(e))\n        raise\n```\n\n### Actual outcome\n\n![Image](https://github.com/user-attachments/assets/fd27ca1f-0d43-40c7-b8f4-cfcd474c9a1e)\n\n```\n---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\nCell In[2], line 20\n     18 for i in range(300):\n     19     try:\n---\u003e 20         try_once()\n     21     except Exception as e:\n     22         print('FAILED at iteration', i, '-\u003e', repr(e))\n\nCell In[2], line 13, in try_once()\n     10 fig, axs = plt.subplots(10, 10, num=fig, squeeze=False)\n     12 for ax in axs.flat:\n---\u003e 13     plt.sca(ax)  # \u003c-- intermittently raises\n     14     plt.plot([1, 2, 3])\n     15     fig.canvas.draw_idle()\n\nFile ~/ipympl-debug/issue/.venv/lib/python3.12/site-packages/matplotlib/pyplot.py:1376, in sca(ax)\n   1372 # Mypy sees ax.figure as potentially None,\n   1373 # but if you are calling this, it won't be None\n   1374 # Additionally the slight difference between `Figure` and `FigureBase` mypy catches\n   1375 fig = ax.get_figure(root=False)\n-\u003e 1376 figure(fig)  # type: ignore[arg-type]\n   1377 fig.sca(ax)\n\nFile ~/ipympl-debug/issue/.venv/lib/python3.12/site-packages/matplotlib/pyplot.py:995, in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)\n    993 root_fig = num.get_figure(root=True)\n    994 if root_fig.canvas.manager is None:\n--\u003e 995     raise ValueError(\"The passed figure is not managed by pyplot\")\n    996 elif (any(param is not None for param in [figsize, dpi, facecolor, edgecolor])\n    997       or not frameon or kwargs) and root_fig.canvas.manager.num in allnums:\n    998     _api.warn_external(\n    999         \"Ignoring specified arguments in this call because figure \"\n   1000         f\"with num: {root_fig.canvas.manager.num} already exists\")\n\nValueError: The passed figure is not managed by pyplot\n```\n\n### Expected outcome\n\nMosaicked plots will be shown without errors.\n\n### Additional information\n\n### Observed state at failure\n\nAt the moment the exception occurs:\n- `root_fig.canvas.manager is None`\n- but the corresponding `FigureManager` still exists in `matplotlib._pylab_helpers.Gcf` (so pyplot still manages the figure)\n\nSo pyplot’s “managed figure” check is making a false negative.\n\n### Where the exception comes from\n\n`plt.sca(ax)` calls `pyplot.figure(fig)` internally.\nWhen passed a `Figure`, `pyplot.figure()` currently checks only:\n\n```python\nroot_fig = num.get_figure(root=True)\nif root_fig.canvas.manager is None:\n    raise ValueError(\"The passed figure is not managed by pyplot\")\n```\n\nIn this bug, `canvas.manager` is temporarily/incorrectly `None` even though the manager still exists in `Gcf`.\n\n### Proposed fix\n\nIf `root_fig.canvas.manager is None`, fall back to a `Gcf` lookup to find the manager whose `m.canvas.figure is root_fig`, and reattach it.\n\n```python\nmanager = root_fig.canvas.manager\nif manager is None:\n    for m in _pylab_helpers.Gcf.get_all_fig_managers():\n        if getattr(getattr(m, \"canvas\", None), \"figure\", None) is root_fig:\n            manager = m\n            root_fig.canvas.manager = m\n            break\nif manager is None:\n    raise ValueError(...)\n```\n\nThis same logic eliminates the failures in my environment (0/60) when applied as a small monkey patch around `pyplot.figure()`.\n\nThis resembles matplotlib/matplotlib#19380 (same structural cause: `FigureCanvasBase.__init__` sets `self.manager=None` after replacing `figure.canvas`).\n\n### Operating system\n\nUbuntu 24\n\n### Matplotlib Version\n\n3.10.8\n\n### ipympl Version\n\n0.10.0\n\n### Matplotlib Backend\n\nwidget\n\n### Python version\n\nPython 3.12.3\n\n### Jupyter version\n\njupyter lab --version: 4.5.4\n\n### Installation\n\nuv","author":{"url":"https://github.com/michitaro","@type":"Person","name":"michitaro"},"datePublished":"2026-03-02T05:29:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/622/ipympl/issues/622"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b2348aa7-f524-a344-fa6b-1b4380400adb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE78C:1A6FEB:13AEE6E:1B0D20D:6A53D451
html-safe-nonce95a249cd8ce3ae888e80549f6c76f85f05b6957c4e837ed3d73ccce4f631a5ad
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzhDOjFBNkZFQjoxM0FFRTZFOjFCMEQyMEQ6NkE1M0Q0NTEiLCJ2aXNpdG9yX2lkIjoiMzU2MTM4NDY0MTY1NDE1MDIyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace0bb09d61e10a5dad7032545749f07be6f1cca842923c6ce6b9c756bd2f67ddf
hovercard-subject-tagissue:4037614050
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/ipympl/622/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f7c4634875ac2a300cb08393b046c3c82cc67a8b9e84ca6145f549dbe7bd3608/matplotlib/ipympl/issues/622
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f7c4634875ac2a300cb08393b046c3c82cc67a8b9e84ca6145f549dbe7bd3608/matplotlib/ipympl/issues/622
og:image:altBug summary When using Matplotlib with ipympl (%matplotlib widget) in JupyterLab, I intermittently get: ValueError: The passed figure is not managed by pyplot This happens with standard pyplot usag...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemichitaro
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/ipympl git https://github.com/matplotlib/ipympl.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id63877123
octolytics-dimension-repository_nwomatplotlib/ipympl
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id63877123
octolytics-dimension-repository_network_root_nwomatplotlib/ipympl
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
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/31223#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fipympl%2Fissues%2F622
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%2Fipympl%2Fissues%2F622
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%2Fipympl
Reloadhttps://github.com/matplotlib/matplotlib/issues/31223
Reloadhttps://github.com/matplotlib/matplotlib/issues/31223
Reloadhttps://github.com/matplotlib/matplotlib/issues/31223
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/31223
matplotlib https://github.com/matplotlib
ipymplhttps://github.com/matplotlib/ipympl
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fipympl
Fork 234 https://github.com/login?return_to=%2Fmatplotlib%2Fipympl
Star 1.7k https://github.com/login?return_to=%2Fmatplotlib%2Fipympl
Code https://github.com/matplotlib/ipympl
Issues 157 https://github.com/matplotlib/ipympl/issues
Pull requests 14 https://github.com/matplotlib/ipympl/pulls
Actions https://github.com/matplotlib/ipympl/actions
Projects https://github.com/matplotlib/ipympl/projects
Security and quality 0 https://github.com/matplotlib/ipympl/security
Insights https://github.com/matplotlib/ipympl/pulse
Code https://github.com/matplotlib/ipympl
Issues https://github.com/matplotlib/ipympl/issues
Pull requests https://github.com/matplotlib/ipympl/pulls
Actions https://github.com/matplotlib/ipympl/actions
Projects https://github.com/matplotlib/ipympl/projects
Security and quality https://github.com/matplotlib/ipympl/security
Insights https://github.com/matplotlib/ipympl/pulse
[Bug]: Intermittent ValueError: The passed figure is not managed by pyplot with ipympl (%matplotlib widget)https://github.com/matplotlib/matplotlib/issues/31223#top
https://github.com/michitaro
michitarohttps://github.com/michitaro
on Mar 2, 2026https://github.com/matplotlib/ipympl/issues/622#issue-4037614050
https://private-user-images.githubusercontent.com/3928908/556714029-fd27ca1f-0d43-40c7-b8f4-cfcd474c9a1e.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODM4NzkwMzgsIm5iZiI6MTc4Mzg3ODczOCwicGF0aCI6Ii8zOTI4OTA4LzU1NjcxNDAyOS1mZDI3Y2ExZi0wZDQzLTQwYzctYjhmNC1jZmNkNDc0YzlhMWUuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MTJUMTc1MjE4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODNjMTQ2N2FhZGFiMDE4MGExNGNmMDJkNTY3YTFhNjJjYmRlZDcxYTgwZmU0YTg1NzU0MTk4MTYzOWZiZTFlNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGZ2lmIn0.iffW39-15JFAI8dqMgabYcj5pJRq_Mv0TgadIhdLB0M
matplotlib/matplotlib#19380https://github.com/matplotlib/matplotlib/issues/19380
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.