Title: [Bug]: DPI keeps doubling when creating a new MatPlotLib QtWidget in qt6 · Issue #26380 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: DPI keeps doubling when creating a new MatPlotLib QtWidget in qt6 · Issue #26380 · matplotlib/matplotlib
X Title: [Bug]: DPI keeps doubling when creating a new MatPlotLib QtWidget in qt6 · Issue #26380 · matplotlib/matplotlib
Description: Bug summary I ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reason keeps increasing the sizes of my chart el...
Open Graph Description: Bug summary I ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reason k...
X Description: Bug summary I ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reas...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/26380
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: DPI keeps doubling when creating a new MatPlotLib QtWidget in qt6","articleBody":"### Bug summary\r\n\r\nI ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reason keeps increasing the sizes of my chart elements, but *only* when I have display scaling on (e.g. 125%, 150% etc). To illustrate:\r\n\r\n\r\n\r\nSee below for the code, basically I am creating a new plot every time there is a mouse click on that row. Embedding `print(self.chart.figure.dpi)` shows that my plot's dpi keeps doubling every other time I trigger a click. Console output:\r\n\r\n```\r\n100.0\r\n100.0\r\n200.0\r\n200.0\r\n400.0\r\n400.0\r\n```\r\n\r\nI can workaround this by explicitly setting the figure DPI, e.g. figure.dpi = 100 when creating it. But I assume that means I'm giving up display scaling\r\n \r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib\r\n\r\nmatplotlib.use(\"Qt5Agg\")\r\nfrom matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg\r\nfrom matplotlib.figure import Figure\r\nfrom PyQt6.QtWidgets import (\r\n QWidget,\r\n QVBoxLayout, QFrame\r\n)\r\n\r\nclass GraphView(QWidget):\r\n def __init__(self):\r\n super().__init__()\r\n self.layout = QVBoxLayout()\r\n self.separator = None\r\n self.chart = MplCanvas()\r\n\r\n self.figures = None\r\n\r\n self.init_widget()\r\n\r\n def init_widget(self):\r\n self.init_separator()\r\n self.layout.addWidget(self.separator)\r\n self.layout.addWidget(self.chart)\r\n self.setLayout(self.layout)\r\n ...\r\n # Note this is the code that triggers when I click a row.\r\n def update_graph(self, figure):\r\n\r\n self.chart.deleteLater()\r\n self.chart = MplCanvas(fig=figure)\r\n \r\n self.layout.addWidget(self.chart)\r\n self.layout.update()\r\n\r\nclass MplCanvas(FigureCanvasQTAgg):\r\n def __init__(self, fig=Figure()):\r\n super(MplCanvas, self).__init__(fig)\r\n\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nFigure DPI keeps dynamically doubling\r\n\r\n### Expected outcome\r\n\r\nDPI shouldn't double like that, it's madness :frowning_face: \r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\nWindows, Linux\r\n\r\n### Matplotlib Version\r\n\r\n3.6.3\r\n\r\n### Matplotlib Backend\r\n\r\nQtAgg\r\n\r\n### Python version\r\n\r\n3.11.4\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/hydroEng","@type":"Person","name":"hydroEng"},"datePublished":"2023-07-24T10:38:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/26380/matplotlib/issues/26380"}
| 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:bc9ddbcb-136f-2cf0-af9f-d65ffdbd83b2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D60C:2003E5:279133A:34C6139:6A5218AB |
| html-safe-nonce | 0672cf457a2ed489f18e006515977f73a763796b3b9a0f8d9271ccca6d3ac3a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjBDOjIwMDNFNToyNzkxMzNBOjM0QzYxMzk6NkE1MjE4QUIiLCJ2aXNpdG9yX2lkIjoiMjE3Njk3Mjk4OTcyNzM4MTY3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 771005f23eea5caa5b025739f94ce1c8d59509809b929b2fc4e72ed1690cc38b |
| hovercard-subject-tag | issue:1818144115 |
| 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/26380/issue_layout |
| twitter:image | https://opengraph.githubassets.com/387c1fa68548d4c2560b8285593518ecbf0369406dba4bd85185b78754edc34d/matplotlib/matplotlib/issues/26380 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/387c1fa68548d4c2560b8285593518ecbf0369406dba4bd85185b78754edc34d/matplotlib/matplotlib/issues/26380 |
| og:image:alt | Bug summary I ran into this bizarre bug, I am not sure if it's a skill issue on my end, but I am trying to embed a plot in my qt6 application. Allowing the user to plot and replot for some reason k... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hydroEng |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width