Title: [Bug]: Backend falls back to Agg even though TkAgg will work · Issue #31715 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Backend falls back to Agg even though TkAgg will work · Issue #31715 · matplotlib/matplotlib
X Title: [Bug]: Backend falls back to Agg even though TkAgg will work · Issue #31715 · matplotlib/matplotlib
Description: Bug summary I've set MPLBACKEND to be "TkAgg". When I import matplotlib.pyplot, the backend switches to "agg". I'm assuming this is some fallback behavior, which would be understandable except for the fact that TkAgg works just fine If I...
Open Graph Description: Bug summary I've set MPLBACKEND to be "TkAgg". When I import matplotlib.pyplot, the backend switches to "agg". I'm assuming this is some fallback behavior, which would be understandable except for ...
X Description: Bug summary I've set MPLBACKEND to be "TkAgg". When I import matplotlib.pyplot, the backend switches to "agg". I'm assuming this is some fallback behavior, which would b...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31715
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Backend falls back to Agg even though TkAgg will work","articleBody":"### Bug summary\n\nI've set MPLBACKEND to be \"TkAgg\". When I import `matplotlib.pyplot`, the backend switches to \"agg\". I'm assuming this is some fallback behavior, which would be understandable except for the fact that TkAgg works just fine\n\nIf I manually set backend with `matplotlib.use(\"TkAgg\")` before importing pyplot, things work as expected. \n\nI would like to avoid having to set the backend in python code, since I might use this with other backends as well\n\n### Code for reproduction\n\n```Python\n# test1.py\nimport matplotlib\nmatplotlib.use(\"TkAgg\")\nimport matplotlib.pyplot as plt\nassert plt.get_backend() == \"TkAgg\" # This works. Plotting also uses Tk as expected\n\n# test2.py\nimport matplotlib.pyplot as plt\nassert plt.get_backend() == \"TkAgg\" # AssertError. Got \"agg\" instead\n```\n\n### Actual outcome\n\nNo output for `test1.py`\n\nAssertionError for `test2.py`\n\n### Expected outcome\n\nNo output for either\n\n### Additional information\n\nOutput with DEBUG level logging, in case that might prove useful\n\n```\nDEBUG:matplotlib:matplotlib data path: xxxxxREDACTEDxxxxx/.venv/lib/python3.13/site-packages/matplotlib/mpl-data\nDEBUG:matplotlib:CONFIGDIR=xxxxxREDACTEDxxxxx\nDEBUG:matplotlib:interactive is False\nDEBUG:matplotlib:platform is linux\nDEBUG:matplotlib:CACHEDIR=xxxxxREDACTEDxxxxx\nDEBUG:matplotlib.font_manager:Using fontManager instance from xxxxxREDACTEDxxxxx/fontlist-v390.json\nDEBUG:matplotlib.pyplot:Loaded backend agg version v2.2.\n```\n\n### Operating system\n\nNixOS\n\n### Matplotlib Version\n\n3.10.9\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.13.12\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nuv","author":{"url":"https://github.com/parthkalgaonkar","@type":"Person","name":"parthkalgaonkar"},"datePublished":"2026-05-20T03:30:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/31715/matplotlib/issues/31715"}
| 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:73a582a0-4651-a663-a59a-f9057da4649d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C38E:B267E:B42645:F584B2:6A51ECBB |
| html-safe-nonce | 4fe582b9d7aa826a13358d736e79d590979e995dc8b9e6d4ca82e66ffc19c1af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzhFOkIyNjdFOkI0MjY0NTpGNTg0QjI6NkE1MUVDQkIiLCJ2aXNpdG9yX2lkIjoiNTgzMjU0NDI2MDk0NDE2MTk3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 69f287d0d4998aaf06579ff19db7e2ba1e1198b6147cceb9dae80100b792d3d1 |
| hovercard-subject-tag | issue:4482873713 |
| 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/31715/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78e332a471354c19333e18e7e511a9bbfa9a09fe542e0aa8189bcade6cd59aeb/matplotlib/matplotlib/issues/31715 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78e332a471354c19333e18e7e511a9bbfa9a09fe542e0aa8189bcade6cd59aeb/matplotlib/matplotlib/issues/31715 |
| og:image:alt | Bug summary I've set MPLBACKEND to be "TkAgg". When I import matplotlib.pyplot, the backend switches to "agg". I'm assuming this is some fallback behavior, which would be understandable except for ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | parthkalgaonkar |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width