Title: [ENH]: Improve plt.arrow default head shape · Issue #22379 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Improve plt.arrow default head shape · Issue #22379 · matplotlib/matplotlib
X Title: [ENH]: Improve plt.arrow default head shape · Issue #22379 · matplotlib/matplotlib
Description: Problem The default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/ This means that in order to get a usable arrow you need to...
Open Graph Description: Problem The default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/ This means that in...
X Description: Problem The default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/ This means that in...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22379
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Improve plt.arrow default head shape","articleBody":"### Problem\r\n\r\nThe default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/\r\n\r\nThis means that in order to get a usable arrow you need to mess around with options such as `head_length` which can be tricky to learn about. \r\n\r\n### Proposed solution\r\n\r\nUse a new heuristic for head sizing as a default behavior. \r\n\r\n@kmdalton suggested the below function `norm_arrow` which you can see gives better defaults in two basic test cases.\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, axes = plt.subplots(2,2)\r\n\r\nlims = (\r\n [-1, 1],\r\n [-10,10],\r\n)\r\n\r\ndef norm_arrow(ax, x1, y1, x2, y2, head_scale=0.1, head_width=None, **kwargs):\r\n norm = np.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))\r\n l = head_scale*norm\r\n w = head_width if head_width is not None else 0.5*l\r\n ax.arrow(x1, y1, x2, y2, head_width=w, head_length=l, length_includes_head=True, **kwargs)\r\n\r\naxes[0][1].set_title(\"Norm based default\")\r\naxes[0][0].set_title(\"Current Default\")\r\n\r\nfor axs, lim in zip(axes, lims):\r\n axs[0].set_ylim(lim)\r\n axs[0].set_xlim(lim)\r\n axs[1].set_ylim(lim)\r\n axs[1].set_xlim(lim)\r\n\r\n axs[0].arrow( 0, 0, lim[1]/2, lim[1]/2, fc=\"k\", ec=\"k\" )\r\n norm_arrow(axs[1], 0, 0, lim[1]/2, lim[1]/2, fc=\"k\", ec=\"k\" )\r\n\r\nplt.show()\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/ianhi","@type":"Person","name":"ianhi"},"datePublished":"2022-02-02T17:45:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/22379/matplotlib/issues/22379"}
| 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:a16b1ded-9d2b-e656-ccb2-e7f73fd820cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93B4:2D29C2:28C5306:379A78F:6A543FEB |
| html-safe-nonce | 2dd94b31bd11dc551faf3d786746d5e71ff64c27dce52d1d8dfce284944a8904 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0I0OjJEMjlDMjoyOEM1MzA2OjM3OUE3OEY6NkE1NDNGRUIiLCJ2aXNpdG9yX2lkIjoiNDEwMDkyNDQ3MDk3NzAwMzMxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1118495c73cce9b70509a19194e227ca4ff475b2d74483643bdab4eb40504f70 |
| hovercard-subject-tag | issue:1122216404 |
| 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/22379/issue_layout |
| twitter:image | https://opengraph.githubassets.com/451f8d242e682d23f2480d522b7a81e77c84373c8399904445c60c4c56c90fe0/matplotlib/matplotlib/issues/22379 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/451f8d242e682d23f2480d522b7a81e77c84373c8399904445c60c4c56c90fe0/matplotlib/matplotlib/issues/22379 |
| og:image:alt | Problem The default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/ This means that in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ianhi |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width