Title: pdf backend displaces patches · Issue #3364 · matplotlib/matplotlib · GitHub
Open Graph Title: pdf backend displaces patches · Issue #3364 · matplotlib/matplotlib
X Title: pdf backend displaces patches · Issue #3364 · matplotlib/matplotlib
Description: I try to draw a circle in display coordinates around a point to avoid stretching when the axes are not equal. Using the pdf backend, the following code will give me a circle that is not centered on the point anymore: #!/usr/bin/env pytho...
Open Graph Description: I try to draw a circle in display coordinates around a point to avoid stretching when the axes are not equal. Using the pdf backend, the following code will give me a circle that is not centered on...
X Description: I try to draw a circle in display coordinates around a point to avoid stretching when the axes are not equal. Using the pdf backend, the following code will give me a circle that is not centered on...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/3364
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pdf backend displaces patches","articleBody":"I try to draw a circle in display coordinates around a point to avoid stretching when the axes are not equal. Using the pdf backend, the following code will give me a circle that is not centered on the point anymore:\r\n\r\n```python\r\n#!/usr/bin/env python\r\n# -*- coding: utf-8 -*-\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.patches as mpatches\r\nimport ipdb\r\nfig = plt.figure()\r\nax = fig.add_subplot(1,1,1)\r\n# plot two points\r\nax.plot((0.2,0.7),(0.5,0.5), \"o\")\r\nax.set_xlim((0,1))\r\n# get the display coordinates\r\nx, y = ax.transData.transform((0.2,0.5))\r\n# plot a circle around the point\r\ncircle = mpatches.Circle((x,y),50,fill=None)\r\n# add to figure\r\nfig.artists.append(circle)\r\n\r\n# save to pdf - circle will not be centered on (0.2,0.5)\r\nfig.savefig(\"displaced.pdf\")\r\n# save to pdf - circle will not be centered on (0.2,0.5)\r\nfig.savefig(\"displaced.pdf\", dpi=fig.dpi)\r\n# save to png - circle will not be centered on (0.2,0.5)\r\nfig.savefig(\"displaced.png\")\r\n# save to png - circle will be centered on (0.2,0.5)\r\nfig.savefig(\"displaced.png\", dpi=fig.dpi)\r\n# show plot - circle will be centered\r\nplt.show(block=True)\r\n```\r\n\r\nThe reason for this can be found in`FigureCanvasPdf.print_pdf()`\r\n\r\n```\r\ndef print_pdf(self, filename, **kwargs):\r\n image_dpi = kwargs.get('dpi', 72) # dpi to use for images\r\n self.figure.set_dpi(72) # there are 72 pdf points to an inch\r\n```\r\n\r\nsuch that the input dpi will be ignored and the scaling will be off at some point. It seems like `RendererPDF` can handle arbitrary dpi, as it uses a scaling factor to `72dpi`, and a change to\r\n\r\n```\r\n self.figure.set_dpi(image_dpi)\r\n```\r\n\r\nsolved my problem. I'm not sure though if this is just a typo or a quick fix to some other problem that is not documented here. If someone can ok this, I will open a pull request.\r\n\\ Edit\r\nI guess I missunderstood the idea behind this, since I just reverted any scaling altogether. Then I don't really know, why this is happening.\r\n","author":{"url":"https://github.com/mvllngr","@type":"Person","name":"mvllngr"},"datePublished":"2014-08-12T13:40:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/3364/matplotlib/issues/3364"}
| 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:b233a46a-470d-6a57-334f-96d41a300659 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A80:C1E1E:F8B02C:14DC6DE:6A529705 |
| html-safe-nonce | 28398be53713c26436591908261ad0258c51e917b1274a9296bc808c55e10d7b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTgwOkMxRTFFOkY4QjAyQzoxNERDNkRFOjZBNTI5NzA1IiwidmlzaXRvcl9pZCI6IjE1MDYxMTg4NjM1MzE3MTAyMTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9e3d3c86cfd79cdb921ed9672d18b7e0bb98564283abfc34e716cb866d6e8a35 |
| hovercard-subject-tag | issue:40055611 |
| 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/3364/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b3ca3b79d168229817c64cc1ac9cc4e91affddbf888e114dfdf939f8927a1a36/matplotlib/matplotlib/issues/3364 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b3ca3b79d168229817c64cc1ac9cc4e91affddbf888e114dfdf939f8927a1a36/matplotlib/matplotlib/issues/3364 |
| og:image:alt | I try to draw a circle in display coordinates around a point to avoid stretching when the axes are not equal. Using the pdf backend, the following code will give me a circle that is not centered on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mvllngr |
| 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