Title: Test layout with big descenders and multiple lines inconsistent. · Issue #11498 · matplotlib/matplotlib · GitHub
Open Graph Title: Test layout with big descenders and multiple lines inconsistent. · Issue #11498 · matplotlib/matplotlib
X Title: Test layout with big descenders and multiple lines inconsistent. · Issue #11498 · matplotlib/matplotlib
Description: Bug report Follow up #11468 If we have multiline text with big descenders (i.e. $\sum_i x$) then the layout mechanism in Text._get_layout() doesn't handle the big descenders properly. Note that _get_layout() gives us the bounding box for...
Open Graph Description: Bug report Follow up #11468 If we have multiline text with big descenders (i.e. $\sum_i x$) then the layout mechanism in Text._get_layout() doesn't handle the big descenders properly. Note that _ge...
X Description: Bug report Follow up #11468 If we have multiline text with big descenders (i.e. $\sum_i x$) then the layout mechanism in Text._get_layout() doesn't handle the big descenders properly. Note that...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11498
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Test layout with big descenders and multiple lines inconsistent.","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\nFollow up #11468 \r\n\r\nIf we have multiline text with big descenders (i.e. `$\\sum_i x$`) then the layout mechanism in `Text._get_layout()` doesn't handle the big descenders properly. Note that `_get_layout()` gives us the bounding box for `text.get_window_extent` so this causes problems for anything that needs to know where the text is and what its size is. \r\n\r\n1. The layout is fine for single lines even large descenders. (first three text objects on each line)\r\n2. For two lines with the same descend the layout is fine (last text object on each line)\r\n3. For mixed size descenders (`test` and ` $\\sum_i x$`) the layout is erroneous. If the big descender comes first, the layout box is too big; conversely if it comes second. \r\n\r\nI keep chasing around solutions, but the algorithm is a bit idiosyncratic so thought I'd post here if anyone had institutional knowledge. \r\n\r\n\r\n\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.patches as mpatches\r\n\r\nfig, ax = plt.subplots(constrained_layout=False)\r\n\r\nax.set_xlim([0, 1.4])\r\nax.set_ylim([0, 2])\r\nax.axhline(0.5, color='C2', linewidth=0.3)\r\nsts = ['Line', '2 Lines g\\n 2nd Line g', '$\\sum_i x $', 'hi $\\sum_i x $\\ntest', 'test\\n $\\sum_i x $', '$\\sum_i x $\\n $\\sum_i x $']\r\n\r\nfor nn, st in enumerate(sts):\r\n tt = ax.text(0.2 * nn + 0.1, 0.5, st, horizontalalignment='center',\r\n verticalalignment='bottom')\r\n bb = tt.get_window_extent(fig.canvas.get_renderer())\r\n bbt = bb.inverse_transformed(ax.transAxes)\r\n r = mpatches.Rectangle((0,0), 1, 1, clip_on=False, transform=ax.transAxes)\r\n r.set_bounds(bbt.bounds)\r\n ax.add_patch(r)\r\nax.text(1.2, 0.5, 'Bottom align', color='C2')\r\n\r\n\r\nif 1:\r\n\r\n ax.axhline(1.3, color='C2', linewidth=0.3)\r\n for nn, st in enumerate(sts):\r\n tt = ax.text(0.2 * nn + 0.1, 1.3, st, horizontalalignment='center',\r\n verticalalignment='top')\r\n bb = tt.get_window_extent(fig.canvas.get_renderer())\r\n bbt = bb.inverse_transformed(ax.transAxes)\r\n r = mpatches.Rectangle((0,0), 1, 1, clip_on=False, transform=ax.transAxes)\r\n r.set_bounds(bbt.bounds)\r\n ax.add_patch(r)\r\n ax.text(1.2, 1.3, 'Top align', color='C2')\r\n\r\n\r\n ax.axhline(1.8, color='C2', linewidth=0.3)\r\n for nn, st in enumerate(sts):\r\n tt = ax.text(0.2 * nn + 0.1, 1.8, st, horizontalalignment='center',\r\n verticalalignment='baseline')\r\n bb = tt.get_window_extent(fig.canvas.get_renderer())\r\n bbt = bb.inverse_transformed(ax.transAxes)\r\n r = mpatches.Rectangle((0,0), 1, 1, clip_on=False, transform=ax.transAxes)\r\n r.set_bounds(bbt.bounds)\r\n ax.add_patch(r)\r\n ax.text(1.2, 1.8, 'Baseline align', color='C2')\r\n\r\n\r\n ax.axhline(0.1, color='C2', linewidth=0.3)\r\n\r\n for nn, st in enumerate(sts):\r\n tt = ax.text(0.2 * nn + 0.1, 0.1, st, horizontalalignment='center',\r\n verticalalignment='bottom', rotation=20)\r\n bb = tt.get_window_extent(fig.canvas.get_renderer())\r\n bbt = bb.inverse_transformed(ax.transAxes)\r\n r = mpatches.Rectangle((0,0), 1, 1, clip_on=False, transform=ax.transAxes)\r\n r.set_bounds(bbt.bounds)\r\n ax.add_patch(r)\r\n ax.text(1.2, 0.1, 'Bot align, rot20', color='C2')\r\n\r\n\r\nbb = tt.get_window_extent(fig.canvas.get_renderer())\r\nbbt = bb.inverse_transformed(ax.transAxes)\r\nr = mpatches.Rectangle((0,0), 1, 1, clip_on=False, transform=ax.transAxes)\r\nr.set_bounds(bbt.bounds)\r\nax.add_patch(r)\r\n\r\nfig.savefig('Old.png')\r\n\r\nplt.show()\r\n```\r\n","author":{"url":"https://github.com/jklymak","@type":"Person","name":"jklymak"},"datePublished":"2018-06-24T17:04:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/11498/matplotlib/issues/11498"}
| 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:b840155d-8d8a-67ad-de77-4ee24dcd9ef2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9018:1C1C74:52CA10:6EE8AC:6A5596B0 |
| html-safe-nonce | 7bf9ac492f8492640ba1268837f63de6ebe440c5f28893d978f3a067d9204554 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDE4OjFDMUM3NDo1MkNBMTA6NkVFOEFDOjZBNTU5NkIwIiwidmlzaXRvcl9pZCI6IjIwNTYxNjI5NTEzMjk4NDY5NjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 06cd3be724bdcecf4ca58a9cdf75674bdfcc06b4fa3d2389228a248b1527301a |
| hovercard-subject-tag | issue:335195203 |
| 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/11498/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bc82432f855c6dc079c1ac43faa9a98d55ab19f1164c933ca5f57ef1602f57bf/matplotlib/matplotlib/issues/11498 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bc82432f855c6dc079c1ac43faa9a98d55ab19f1164c933ca5f57ef1602f57bf/matplotlib/matplotlib/issues/11498 |
| og:image:alt | Bug report Follow up #11468 If we have multiline text with big descenders (i.e. $\sum_i x$) then the layout mechanism in Text._get_layout() doesn't handle the big descenders properly. Note that _ge... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jklymak |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | aa21baa44893467b0b640d0300538f84ca8c475b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width