Title: Dragging Legend not working properly · Issue #24755 · matplotlib/matplotlib · GitHub
Open Graph Title: Dragging Legend not working properly · Issue #24755 · matplotlib/matplotlib
X Title: Dragging Legend not working properly · Issue #24755 · matplotlib/matplotlib
Description: Bug summary This may not be a bug. It is my use case. I have embedded matplotlib in PyQt5 and I am using Ctrl+C to copy the figure to clipboard (for pasting to ppt) So in the minimum example attached, pressing Ctrl+C reduces figure size ...
Open Graph Description: Bug summary This may not be a bug. It is my use case. I have embedded matplotlib in PyQt5 and I am using Ctrl+C to copy the figure to clipboard (for pasting to ppt) So in the minimum example attach...
X Description: Bug summary This may not be a bug. It is my use case. I have embedded matplotlib in PyQt5 and I am using Ctrl+C to copy the figure to clipboard (for pasting to ppt) So in the minimum example attach...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24755
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dragging Legend not working properly ","articleBody":"### Bug summary\r\n\r\nThis may not be a bug. It is my use case.\r\n\r\nI have embedded matplotlib in PyQt5 and I am using `Ctrl+C` to copy the figure to clipboard (for pasting to ppt)\r\n\r\nSo in the minimum example attached, pressing `Ctrl+C` reduces figure size to specified size (6x4). This is kind of a print preview for me. So I adjust legend/annotations in the smaller figure.\r\n\r\nDragging legend is not working properly in the smaller figure. It used to work in older versions for me. So I went through the changes. Reverting the change done in the following line of `blit` function of `/backends/backend_qt.py` fixes the problem (Changed as part of #17478)\r\n\r\n`self.repaint(l, self.rect().height() - t, w, h)`\r\n to\r\n ` self.repaint(l, int(self.renderer.height / self.device_pixel_ratio)- t, w, h)`\r\n\r\nFor the normal figure `self.rect().height()` is equal to `int(self.renderer.height / self.device_pixel_ratio)`\r\n\r\nBut for the smaller figure `self.rect().height()` is different from `int(self.renderer.height / self.device_pixel_ratio)`\r\n\r\nIs this ok?\r\n\r\nThanks\r\n\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport io\r\nimport sys\r\nfrom PyQt5.QtWidgets import QWidget, QApplication, QShortcut, QVBoxLayout\r\nfrom PyQt5.QtCore import QMimeData\r\nfrom PyQt5.QtGui import QKeySequence\r\n\r\nfrom matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas\r\nfrom matplotlib.figure import Figure\r\n\r\nimport random\r\n\r\nclass Window(QWidget):\r\n def __init__(self, parent=None):\r\n super(Window, self).__init__(parent)\r\n self.figure = Figure()\r\n\r\n data = [random.random() for _ in range(10)]\r\n\r\n ax = self.figure.add_subplot(111)\r\n ax.plot(data, '*-',label='RandomData')\r\n legend = ax.legend()\r\n \r\n self.canvas = FigureCanvas(self.figure)\r\n self.canvas.draw()\r\n\r\n legend.set_draggable(True,use_blit=True) # Dragging is not ok in smaller figure/ ok in normal figure\r\n # legend.set_draggable(True) # Dragging is ok in smaller figure when blitting is off\r\n\r\n\r\n ctc = QShortcut(QKeySequence(\"Ctrl+C\"), self)\r\n ctc.activated.connect(self.copy_to_clipboard)\r\n\r\n layout = QVBoxLayout()\r\n layout.addWidget(self.canvas)\r\n self.setLayout(layout)\r\n\r\n def copy_to_clipboard(self):\r\n fig = self.canvas.figure\r\n fig.set_size_inches(6,4)\r\n buf = io.BytesIO()\r\n fig.savefig(buf,dpi=300,transparent=True,bbox_inches='tight')\r\n mimeData = QMimeData()\r\n mimeData.setData(\"PNG\",buf.getvalue())\r\n QApplication.clipboard().setMimeData(mimeData)\r\n buf.close()\r\n\r\n \r\nif __name__ == '__main__':\r\n app = QApplication(sys.argv)\r\n main = Window()\r\n main.showMaximized()\r\n sys.exit(app.exec_())\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\n\r\n\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\nWindows\r\n\r\n### Matplotlib Version\r\n\r\n3.6.2\r\n\r\n### Matplotlib Backend\r\n\r\nPyQt5\r\n\r\n### Python version\r\n\r\n3.8.10\r\n\r\n### Jupyter version\r\n\r\nNA\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/inxp","@type":"Person","name":"inxp"},"datePublished":"2022-12-17T06:05:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/24755/matplotlib/issues/24755"}
| 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:675d244f-06f4-4824-e186-3bdcc7716f32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE68:9FC62:1FAEAD:2AA583:6A5287F2 |
| html-safe-nonce | 221e02f898e68c15afacc9e41b8ea624c12288e8167af357f1cc25377789583b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTY4OjlGQzYyOjFGQUVBRDoyQUE1ODM6NkE1Mjg3RjIiLCJ2aXNpdG9yX2lkIjoiNjU2MTQ2OTYyNjMzNjgzOTY2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7b0f59fff3ea75cf100b4c87cf7094b08d152b779a27f7e686c4530ced66f5cb |
| hovercard-subject-tag | issue:1501204148 |
| 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/24755/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70a27c4d584fc2abf6552d5b347ed77f6240af03b34d0aa7141ef05865423d58/matplotlib/matplotlib/issues/24755 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70a27c4d584fc2abf6552d5b347ed77f6240af03b34d0aa7141ef05865423d58/matplotlib/matplotlib/issues/24755 |
| og:image:alt | Bug summary This may not be a bug. It is my use case. I have embedded matplotlib in PyQt5 and I am using Ctrl+C to copy the figure to clipboard (for pasting to ppt) So in the minimum example attach... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | inxp |
| 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