Title: [Bug]: Erroneous text wrapping when text vertical position is 1.0 · Issue #31537 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Erroneous text wrapping when text vertical position is 1.0 · Issue #31537 · matplotlib/matplotlib
X Title: [Bug]: Erroneous text wrapping when text vertical position is 1.0 · Issue #31537 · matplotlib/matplotlib
Description: Bug summary Setting Figure.text y to 1.0 results in it not being able to properly adjust line width for text wrapping. Given example makes use of tkinter embedding Code for reproduction import tkinter import matplotlib import matplotlib....
Open Graph Description: Bug summary Setting Figure.text y to 1.0 results in it not being able to properly adjust line width for text wrapping. Given example makes use of tkinter embedding Code for reproduction import tkin...
X Description: Bug summary Setting Figure.text y to 1.0 results in it not being able to properly adjust line width for text wrapping. Given example makes use of tkinter embedding Code for reproduction import tkin...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31537
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Erroneous text wrapping when text vertical position is 1.0","articleBody":"### Bug summary\n\nSetting Figure.text y to 1.0 results in it not being able to properly adjust line width for text wrapping. Given example makes use of tkinter embedding\n\n### Code for reproduction\n\n```Python\nimport tkinter\nimport matplotlib\nimport matplotlib.backends.backend_tkagg\nimport matplotlib.figure\n\n\nmatplotlib.use(\"tkagg\")\n\nmain_window = tkinter.Tk()\ncanvas_figure = matplotlib.figure.Figure(figsize=(1.0, 1.0))\ncanvas_text = canvas_figure.text(0.0, 1.0, \"Helo World! thisisalongassstring aneventextralongassstring\", verticalalignment=\"top\", horizontalalignment=\"left\", multialignment=\"left\", wrap=True, snap=True)\n\nmpl_canvas = matplotlib.backends.backend_tkagg.FigureCanvas(figure=canvas_figure, master=main_window)\n\nmpl_canvas.get_tk_widget().grid(row=0, column=0, rowspan=1, columnspan=1, sticky=\"nsew\")\nmain_window.rowconfigure(0, weight=1)\nmain_window.columnconfigure(0, weight=1)\n\nmain_window.mainloop()\n```\n\n### Actual outcome\n\n\n\u003cimg width=\"374\" height=\"197\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/9116e8ad-63d2-4872-9794-9df5978862d6\" /\u003e\n\nwhen dynamically resizing:\n\u003cimg width=\"376\" height=\"170\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/89d57e5e-89ec-4b6d-aec0-2e98c67efbe4\" /\u003e\n\n### Expected outcome\n\n\u003cimg width=\"295\" height=\"162\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/cd47e39a-9e70-4cb0-a033-fd1d289d1b60\" /\u003e\n\n\u003cimg width=\"617\" height=\"219\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/70881644-b9f0-4240-b44e-9b8d0c2c397e\" /\u003e\n\n### Additional information\n\nWrapping seems to work fine for ranges inside 0-1 but not exactly 1. Simple workaround is to set position not exactly 1 (0.99 in working example). it would be nice however, to be explicit and either warn or handle the exact case as I would argue that it is the natural setting when attempting to position the text on the top. \n\nLooking around, I think the issue has to do with the Text method __get_dist_to_box__ being unable to handle edge cases. Specifically cases where either the text position exceeds the bounds of the figure, or when division by zero occurs due to cosine evaluating to 0.\n\n### Operating system\n\nWindows 10 Pro Version\t22H2 9045.6466\n\n### Matplotlib Version\n\n3.10.8\n\n### Matplotlib Backend\n\ntkagg\n\n### Python version\n\n3.14.4\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/AL4N23","@type":"Person","name":"AL4N23"},"datePublished":"2026-04-20T16:16:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/31537/matplotlib/issues/31537"}
| 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:b3b9f73e-3cda-ee51-65e4-a4ffa1607d15 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7F0:341B39:381FEC:4B8D8A:6A52ECC9 |
| html-safe-nonce | fdeb9c76a0c894d1f8a7e6655634b677371130a75102dfa43e33ab1d38473482 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0YwOjM0MUIzOTozODFGRUM6NEI4RDhBOjZBNTJFQ0M5IiwidmlzaXRvcl9pZCI6IjIzNDcxMDg4NTQ5MTQwMTg1MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | acf708cbf0c9dc6432ebf23f0c4d4c09c1472ec47fa3302a71dc2e2796e1aec8 |
| hovercard-subject-tag | issue:4297112891 |
| 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/31537/issue_layout |
| twitter:image | https://opengraph.githubassets.com/98900b18b6e061b14bc462906d32797c6f02db8f048d5ad2dd318895a3f8dee1/matplotlib/matplotlib/issues/31537 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/98900b18b6e061b14bc462906d32797c6f02db8f048d5ad2dd318895a3f8dee1/matplotlib/matplotlib/issues/31537 |
| og:image:alt | Bug summary Setting Figure.text y to 1.0 results in it not being able to properly adjust line width for text wrapping. Given example makes use of tkinter embedding Code for reproduction import tkin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AL4N23 |
| 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