Title: savefig PDF output - incorrect annotation location · Issue #10844 · matplotlib/matplotlib · GitHub
Open Graph Title: savefig PDF output - incorrect annotation location · Issue #10844 · matplotlib/matplotlib
X Title: savefig PDF output - incorrect annotation location · Issue #10844 · matplotlib/matplotlib
Description: Bug report Annotation beneath legend is positioned correctly on screen and with PNG output generated by savefig(). Annotation location is incorrect for PDF output of savefig() Code for reproduction import matplotlib.pyplot as plt import ...
Open Graph Description: Bug report Annotation beneath legend is positioned correctly on screen and with PNG output generated by savefig(). Annotation location is incorrect for PDF output of savefig() Code for reproduction...
X Description: Bug report Annotation beneath legend is positioned correctly on screen and with PNG output generated by savefig(). Annotation location is incorrect for PDF output of savefig() Code for reproduction...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/10844
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"savefig PDF output - incorrect annotation location","articleBody":"### Bug report\r\n\r\nAnnotation beneath legend is positioned correctly on screen and with PNG output generated by savefig(). Annotation location is incorrect for PDF output of savefig()\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.text\r\n\r\nfig, ax = plt.subplots()\r\n\r\nax.plot([5,1], label=\"Label 1\")\r\nax.plot([3,0], label=\"Label 2\")\r\n\r\nlegend = ax.legend(loc=\"upper right\")\r\n\r\n# Create offset from lower right corner of legend box,\r\n# (1.0,0) is the coordinates of the offset point in the legend coordinate system\r\noffset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))\r\n# Create annotation. Top right corner located -20 pixels below the offset point \r\n# (lower right corner of legend).\r\nax.annotate(\"info_string\", xy=(0,0),size=14,\r\n xycoords='figure fraction', xytext=(0,-20), textcoords=offset, \r\n horizontalalignment='right', verticalalignment='top')\r\n# Draw the canvas for offset to take effect\r\nfig.canvas.draw()\r\n\r\nfig.savefig('plot1.png')\r\nfig.savefig('plot1.pdf')\r\n\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\nThe code produces an on-screen plot with two lines, a legend, and the annotation string 'info_string' located beneath the legend and aligned to the right hand edge of the legend box.\r\nThe code also generates two files;\r\n1) 'plot1.png', which is generated correctly \r\n2) 'plot1.pdf', which is generated incorrectly. The annotation is not visible, as it is in the wrong location (far right of the displayed region).\r\n\r\nThe PNG output is [here](https://i.stack.imgur.com/NuXh6.png), which is what both files should look like.\r\nThe incorrect PDF output is [here](https://i.stack.imgur.com/23PYN.png).\r\n\r\nIf the length of the annotation string in increased (eg. to 'extra_information_string'), the first few characters become visible in the top right corner of the PDF file.\r\n\r\n**Expected outcome**\r\nThe PDF file should show the annotation in the same location as the on screen plot and the PNG file.\r\n\r\n**Software Versions**\r\n * Operating system: Windows 7 Home\r\n * Matplotlib version: 2.2.0 (problem also appears with 1.5.3)\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): Qt5Agg\r\n * Python version: 2.7.14\r\n * Jupyter version (if applicable): N/A \r\nMatplotlib and python were installed using conda from the default channel.\r\nThe problem was observed when running the above code as a script from the command line.\r\n","author":{"url":"https://github.com/delorytheape","@type":"Person","name":"delorytheape"},"datePublished":"2018-03-20T00:58:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/10844/matplotlib/issues/10844"}
| 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:a386efe1-d617-b79c-e3f8-9a6778bd76b5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC08:81E5E:2DA7B8:3F5EBE:6A5846E0 |
| html-safe-nonce | dc100ddb9d5c368c8421be0ca107bbb28c3687d1d878d26f8de86b294f5a1ba6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzA4OjgxRTVFOjJEQTdCODozRjVFQkU6NkE1ODQ2RTAiLCJ2aXNpdG9yX2lkIjoiMjcwNjcwNjYxOTU2NDU3NDQzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49817f1b5c38ac7128b0077fcc0eed248b37bcbb39ebc19e1ccbb1d2c2062877 |
| hovercard-subject-tag | issue:306690547 |
| 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/10844/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15687e636e091e1ffbb782fb010c3cd9d1b847e46dd842b4da92386621130c7a/matplotlib/matplotlib/issues/10844 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15687e636e091e1ffbb782fb010c3cd9d1b847e46dd842b4da92386621130c7a/matplotlib/matplotlib/issues/10844 |
| og:image:alt | Bug report Annotation beneath legend is positioned correctly on screen and with PNG output generated by savefig(). Annotation location is incorrect for PDF output of savefig() Code for reproduction... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | delorytheape |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| 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 | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width