Title: Text alignment · Issue #1180 · matplotlib/matplotlib · GitHub
Open Graph Title: Text alignment · Issue #1180 · matplotlib/matplotlib
X Title: Text alignment · Issue #1180 · matplotlib/matplotlib
Description: Hi, I added a quick patch to allow numerical values for text alignment. It now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So ha = 0 == 'left' ha = 1 == 'right' va = 0 == 'bottom' va...
Open Graph Description: Hi, I added a quick patch to allow numerical values for text alignment. It now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So ha = 0 == 'left'...
X Description: Hi, I added a quick patch to allow numerical values for text alignment. It now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So ha = 0 == 'l...
Mail addresses
matplotlib@2sn.net
matplotlib@2sn.net
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/1180
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Text alignment","articleBody":"Hi,\n\nI added a quick patch to allow numerical values for text alignment.\nIt now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So\nha = 0 == 'left'\nha = 1 == 'right'\nva = 0 == 'bottom'\nva = 1 == 'top'\nva/ha = 0.5 == 'center'\n\nthe cool thing is that values outside [0,1] allow you to some defined distance from a line or symbol that remains well-measured even if you interactively scale the figure.\n\nCan you please add this to MPL?\n\n(also fixed some typos in typo doc)\n\nThis is my first addition here, not sure how to add patches, I can submit a pull request it appears.\n\n-Alexander\n\nhttps://github.com/2sn/matplotlib/compare/master...text-numeric-va-ha\n\nFrom b167849f438e4b77319c51fd603946525823edc0 Mon Sep 17 00:00:00 2001\nFrom: Alexander Heger matplotlib@2sn.net\nDate: Fri, 31 Aug 2012 16:58:04 +1000\nSubject: [PATCH 1/2] ADD - added numeric update for ha and va in Text\n\n---\n\n lib/matplotlib/text.py | 34 +++++++++++++++++++---------------\n 1 file changed, 19 insertions(+), 15 deletions(-)\n\ndiff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py\nindex b00e4cf..b1188de 100644\n--- a/lib/matplotlib/text.py\n+++ b/lib/matplotlib/text.py\n@@ -10,7 +10,7 @@ from matplotlib import cbook\n from matplotlib import rcParams\n import matplotlib.artist as artist\n from matplotlib.artist import Artist\n-from matplotlib.cbook import is_string_like, maxdict\n+from matplotlib.cbook import is_string_like, maxdict, is_numlike\n from matplotlib import docstring\n from matplotlib.font_manager import FontProperties\n from matplotlib.patches import bbox_artist, YAArrow, FancyBboxPatch, \\\n@@ -69,21 +69,21 @@ docstring.interpd.update(Text = \"\"\"\n family [ 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]\n figure a matplotlib.figure.Figure instance\n fontproperties a matplotlib.font_manager.FontProperties instance\n- horizontalalignment or ha [ 'center' | 'right' | 'left' ]\n- horizontalalignment or ha [ 'center' | 'right' | 'left' | fraction text width from left ]\n label any string\n linespacing float\n lod [True | False]\n multialignment ['left' | 'right' | 'center' ]\n name or fontname string eg, ['Sans' | 'Courier' | 'Helvetica' ...]\n position (x,y)\n- rotation [ angle in degrees 'vertical' | 'horizontal'\n- rotation [ angle in degrees | 'vertical' | 'horizontal' ]\n rotation_mode [ None | 'anchor']\n size or fontsize [ size in points | relative size eg 'smaller', 'x-large' ]\n style or fontstyle [ 'normal' | 'italic' | 'oblique']\n text string\n transform a matplotlib.transform transformation instance\n variant [ 'normal' | 'small-caps' ]\n- verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' ]\n- verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' | fraction text height from bottom ]\n visible [True | False]\n weight or fontweight [ 'normal' | 'bold' | 'heavy' | 'light' | 'ultrabold' | 'ultralight']\n x float\n @@ -378,25 +378,29 @@ class Text(Artist):\n if rotation_mode != \"anchor\":\n # compute the text location in display coords and the offsets\n # necessary to align the bbox with that location\n- if halign=='center': offsetx = (xmin + width/2.0)\n- if halign=='center': offsetx = (xmin + width*0.5)\n elif halign=='right': offsetx = (xmin + width)\n- ```\n elif is_numlike(halign): offsetx = xmin + halign * (xmax - xmin)\n else: offsetx = xmin\n ```\n- ```\n if valign=='center': offsety = (ymin + height/2.0)\n ```\n- if valign=='center': offsety = (ymin + height*0.5)\n elif valign=='top': offsety = (ymin + height)\n elif valign=='baseline': offsety = (ymin + height) - baseline\n- ```\n elif is_numlike(valign): offsety = ymin + valign * (ymax - ymin)\n else: offsety = ymin\n else:\n xmin1, ymin1 = cornersHoriz[0]\n xmax1, ymax1 = cornersHoriz[2]\n ```\n- ```\n if halign=='center': offsetx = (xmin1 + xmax1)/2.0\n ```\n- if halign=='center': offsetx = (xmin1 + xmax1)*0.5\n elif halign=='right': offsetx = xmax1\n- ```\n elif is_numlike(halign): offsetx = xmin1 + halign * (xmax1 - xmin1)\n else: offsetx = xmin1\n ```\n- ```\n if valign=='center': offsety = (ymin1 + ymax1)/2.0\n ```\n- if valign=='center': offsety = (ymin1 + ymax1)*0.5\n elif valign=='top': offsety = ymax1\n elif valign=='baseline': offsety = ymax1 - baseline\n- ```\n elif is_numlike(valign): offsety = ymin1 + valign * (ymax1 - ymin1)\n else: offsety = ymin1\n \n offsetx, offsety = M.transform_point((offsetx, offsety))\n ```\n \n @@ -796,11 +800,11 @@ class Text(Artist):\n \"\"\"\n Set the horizontal alignment to one of\n- ```\n ACCEPTS: [ 'center' | 'right' | 'left' ]\n ```\n- ACCEPTS: [ 'center' | 'right' | 'left' | fraction text width from left ]\n \"\"\"\n legal = ('center', 'right', 'left')\n- if align not in legal:\n- raise ValueError('Horizontal alignment must be one of %s' % str(legal))\n- if align not in legal and not is_numlike(align):\n- ```\n raise ValueError('Horizontal alignment must be numeric or one of %s' % str(legal))\n self._horizontalalignment = align\n ```\n \n def set_ma(self, align):\n @@ -811,7 +815,7 @@ class Text(Artist):\n def set_multialignment(self, align):\n \"\"\"\n Set the alignment for multiple lines layout. The layout of the\n- bounding box of all the lines is determined bu the horizontalalignment\n- bounding box of all the lines is determined but the horizontalalignment\n and verticalalignment properties, but the multiline text within that\n box can be\n\n@@ -957,11 +961,11 @@ class Text(Artist):\n \"\"\"\n Set the vertical alignment\n- ACCEPTS: [ 'center' | 'top' | 'bottom' | 'baseline' ]\n- ACCEPTS: [ 'center' | 'top' | 'bottom' | 'baseline' | fraction text height from bottom ]\n \"\"\"\n legal = ('top', 'bottom', 'center', 'baseline')\n- if align not in legal:\n- raise ValueError('Vertical alignment must be one of %s' % str(legal))\n- if align not in legal and not is_numlike(align):\n- ```\n raise ValueError('Vertical alignment must be numeric or one of %s' % str(legal))\n \n self._verticalalignment = align\n ```\n## \n\n1.7.11.4\n\nFrom 076d2ef17d8bb25417ee805a9b9a9221918d230f Mon Sep 17 00:00:00 2001\nFrom: Alexander Heger matplotlib@2sn.net\nDate: Fri, 31 Aug 2012 17:05:23 +1000\nSubject: [PATCH 2/2] BF typo\n\n---\n\n lib/matplotlib/text.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py\nindex b1188de..a22dd64 100644\n--- a/lib/matplotlib/text.py\n+++ b/lib/matplotlib/text.py\n@@ -815,7 +815,7 @@ class Text(Artist):\n def set_multialignment(self, align):\n \"\"\"\n Set the alignment for multiple lines layout. The layout of the\n- bounding box of all the lines is determined but the horizontalalignment\n- bounding box of all the lines is determined by the horizontalalignment\n and verticalalignment properties, but the multiline text within that\n box can be\n## \n\n1.7.11.4\n","author":{"url":"https://github.com/2sn","@type":"Person","name":"2sn"},"datePublished":"2012-08-31T09:58:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/1180/matplotlib/issues/1180"}
| 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:f305675a-1b82-0a40-677d-9f3df2834b1e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E892:2C9FC7:14ACE4C:1B6435E:6A534A15 |
| html-safe-nonce | 5e41e8c921d5cbca84c6bc8dc26d914404e7336ce69ce0a357580e6da1a75837 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODkyOjJDOUZDNzoxNEFDRTRDOjFCNjQzNUU6NkE1MzRBMTUiLCJ2aXNpdG9yX2lkIjoiNDk3NzUzMzQ5NDg1MzA2MTE0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 16836d7dced92a9f397c4144573f0032ce8ee2a664295de03c6e13537d0b5ba5 |
| hovercard-subject-tag | issue:6575204 |
| 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/1180/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78e89aa0cd3e937688f398d1b3db03a0b6e3e95addf962ed2bde1ad5f2a7894c/matplotlib/matplotlib/issues/1180 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78e89aa0cd3e937688f398d1b3db03a0b6e3e95addf962ed2bde1ad5f2a7894c/matplotlib/matplotlib/issues/1180 |
| og:image:alt | Hi, I added a quick patch to allow numerical values for text alignment. It now allows a number that is fraction of text hight or with and is measured relative to bottom or left. So ha = 0 == 'left'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 2sn |
| 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