Title: Invalid pixel ratio update when changing screen resolution · Issue #19656 · matplotlib/matplotlib · GitHub
Open Graph Title: Invalid pixel ratio update when changing screen resolution · Issue #19656 · matplotlib/matplotlib
X Title: Invalid pixel ratio update when changing screen resolution · Issue #19656 · matplotlib/matplotlib
Description: Bug report Bug summary When switching from an external monitor, with a dpi ratio of 1.0, to my MacBook Pro laptop, with a dpi ratio of 2.0, existing PyQt windows containing Matplotlib plots look fine after waking from sleep but switch to...
Open Graph Description: Bug report Bug summary When switching from an external monitor, with a dpi ratio of 1.0, to my MacBook Pro laptop, with a dpi ratio of 2.0, existing PyQt windows containing Matplotlib plots look fi...
X Description: Bug report Bug summary When switching from an external monitor, with a dpi ratio of 1.0, to my MacBook Pro laptop, with a dpi ratio of 2.0, existing PyQt windows containing Matplotlib plots look fi...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19656
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid pixel ratio update when changing screen resolution","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nWhen switching from an external monitor, with a dpi ratio of 1.0, to my MacBook Pro laptop, with a dpi ratio of 2.0, existing PyQt windows containing Matplotlib plots look fine after waking from sleep but switch to a quarter size as soon as I select the window, i.e., the fix in the PR #19123 doesn't seem to work in this scenario.\r\n\r\n**Code for reproduction**\r\n\r\nI am using the [NeXpy package](https://nexpy.github.io/nexpy/), which embeds Matplotlib canvases in separate PyQt5 windows. Each window is added to a dictionary, called `plotviews`, which is available to an embedded Python shell. If I initially plot on my external monitor, I get the following plot:\r\n\r\nIn the shell, I see the following ratios.\r\n```\r\nIn [1]: for pv in plotviews:\r\n print(plotviews[pv].canvas._dpi_ratio, plotviews[pv].canvas._dpi_ratio_prev)\r\n1.0 1.0\r\n1.0 1.0\r\n1.0 1.0\r\n```\r\n**Actual outcome**\r\nWhen I switch to my laptop, the plots look fine initially, but as soon as I select any window, the plot shrinks to quarter size:\r\n\u003cimg width=\"862\" alt=\"laptop-screen\" src=\"https://user-images.githubusercontent.com/1193959/110212448-0bcf6200-7e61-11eb-99fc-bbcbf5e3e072.png\"\u003e\r\n```\r\nIn [2]: for pv in plotviews:\r\n print(plotviews[pv].canvas._dpi_ratio, plotviews[pv].canvas._dpi_ratio_prev)\r\n2.0 1.0\r\n2.0 1.0\r\n2.0 1.0\r\n```\r\nAfter the plots have shrunk, the `_dpi_ratio_prev` has still not been updated.\r\n```\r\nIn [3]: for pv in plotviews:\r\n print(plotviews[pv].canvas._dpi_ratio, plotviews[pv].canvas._dpi_ratio_prev)\r\n2.0 1.0\r\n2.0 1.0\r\n2.0 1.0\r\n```\r\n**Expected outcome**\r\nObviously, the plots should not change size. Selecting the window does not appear to trigger the canvas `showEvent` function. I'm not sure what does. If I force an update, the plot does expand to the correct size. Note that `_dpi_ratio_prev` has been updated after the explicit call to `_update_screen` but only for the third figure. The others are still shrunk.\r\n```\r\nIn [4]: screen=plotviews['Figure 3'].canvas.window().windowHandle()\r\nIn [5]: plotviews['Figure 3'].canvas._update_screen(screen.screen())\r\nIn [6]: for pv in plotviews:\r\n print(plotviews[pv].canvas._dpi_ratio, plotviews[pv].canvas._dpi_ratio_prev)\r\n2.0 1.0\r\n2.0 1.0\r\n2.0 2.0\r\n```\r\nI wonder if the `screenChanged` signal should be connected to `_update_screen` at an earlier stage in initializing the window without depending on a call to `showEvent`.\r\n\r\n**Matplotlib version**\r\n * Operating system: Mac OS X 10.15.7\r\n * Matplotlib version: 3.4.0rc1\r\n * Matplotlib backend: Qt5agg\r\n * Python version: 3.8.6\r\n * PyQt5 version: 5.15.2\r\n\r\nI used pip to update to the latest release candidate within a conda environment.\r\n\r\nEdited to correct reference to the screen.\r\n\r\n","author":{"url":"https://github.com/rayosborn","@type":"Person","name":"rayosborn"},"datePublished":"2021-03-06T16:19:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/19656/matplotlib/issues/19656"}
| 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:8774d327-0c6f-b4f3-baa5-08e875ad876a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0C4:340A4D:23DB0:30235:6A52D75A |
| html-safe-nonce | 094db9cd084c829a7aa7cfc442cd1693e1b5f43bad5f3f7630d3fd68f0b020d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEM0OjM0MEE0RDoyM0RCMDozMDIzNTo2QTUyRDc1QSIsInZpc2l0b3JfaWQiOiI0Mzk5MDIxNjQ2NTU3NjY1MTE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1a0109ec4969ac496d0bd2823bffe0005a9078184c037d4f0a188cd90f64bc08 |
| hovercard-subject-tag | issue:823685928 |
| 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/19656/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8af81cf4ad0e9898b052d6657d459150822614666e990d33b9408ab5ab11ed83/matplotlib/matplotlib/issues/19656 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8af81cf4ad0e9898b052d6657d459150822614666e990d33b9408ab5ab11ed83/matplotlib/matplotlib/issues/19656 |
| og:image:alt | Bug report Bug summary When switching from an external monitor, with a dpi ratio of 1.0, to my MacBook Pro laptop, with a dpi ratio of 2.0, existing PyQt windows containing Matplotlib plots look fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rayosborn |
| 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