Title: [Bug]: compressed layout setting can be forgotten on second save · Issue #24954 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: compressed layout setting can be forgotten on second save · Issue #24954 · matplotlib/matplotlib
X Title: [Bug]: compressed layout setting can be forgotten on second save · Issue #24954 · matplotlib/matplotlib
Description: Bug summary I'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applied the second time a figure is saved. Code for re...
Open Graph Description: Bug summary I'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applied the se...
X Description: Bug summary I'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applie...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24954
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: compressed layout setting can be forgotten on second save","articleBody":"### Bug summary\r\n\r\nI'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applied the second time a figure is saved.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\narr = np.arange(100).reshape((10, 10))\r\n\r\nmatplotlib.rcParams['figure.constrained_layout.use'] = True\r\n\r\nfig, ax_dict = plt.subplot_mosaic('AB;AC', figsize=(6, 9), width_ratios=[3, 2],\r\n layout='compressed')\r\n\r\nfor key in [\"B\", \"C\"]:\r\n ax_dict[key].imshow(arr)\r\n \r\nfig.savefig(\"test1.png\", bbox_inches=\"tight\")\r\nfig.savefig(\"test2.png\", bbox_inches=\"tight\")\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\ntest1.png\r\n\r\n\r\ntest2.png\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nBoth images should look like the first.\r\n\r\n### Additional information\r\n\r\nIf I do not set the `rcParams`, all is well. If I do not set `bbox_inches=\"tight\"` in my calls to `savefig`, the images are identical (but I have too much white space top and bottom). Maybe there is a better option than `bbox_inches=\"tight\"` when using compressed layout?\r\n\r\nFor context, my real example is a script that makes several figures. For most of them I want constrained layout, so I set that once in the `rcParams` for convenience. Only one figure needs \"compressed\", and I am saving twice because I want both a png and a pdf. Fixed it in my current example by just reverting the `rcParams` setting for the one figure.\r\n\r\n### Operating system\r\n\r\nRHEL7\r\n\r\n### Matplotlib Version\r\n\r\n3.6.2 and main\r\n\r\n### Matplotlib Backend\r\n\r\nQtAgg\r\n\r\n### Python version\r\n\r\n3.9 and 3.11\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nconda","author":{"url":"https://github.com/rcomer","@type":"Person","name":"rcomer"},"datePublished":"2023-01-12T13:13:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/24954/matplotlib/issues/24954"}
| 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:adbfbed0-1337-8a3b-9ea4-38d22c73937c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99E8:B9479:86E439:C0A3C9:6A510575 |
| html-safe-nonce | e0fefce52945d1d4ed79b6028f300240da1e6fa364cef4a45f5117ad5ffda5f2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUU4OkI5NDc5Ojg2RTQzOTpDMEEzQzk6NkE1MTA1NzUiLCJ2aXNpdG9yX2lkIjoiODM0MDczNzA3Nzk4NjUyNjU4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ed4c499a935e2eaf7754ae3933d6d5d31dbab6e2845c135d5382221d1abf105c |
| hovercard-subject-tag | issue:1530694076 |
| 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/24954/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb5f89ed23d8ef0999845a2260b4251eb88d8109a17a4953b7211553d0455f2e/matplotlib/matplotlib/issues/24954 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb5f89ed23d8ef0999845a2260b4251eb88d8109a17a4953b7211553d0455f2e/matplotlib/matplotlib/issues/24954 |
| og:image:alt | Bug summary I'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applied the se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rcomer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 38906a4da4e3e9fd88dfeacee232f5932c0c5f7495de3b4efc53ddfac7173d12 |
| 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 | 90441ea9b98e7491aa6ebcd135fccce4e2396f48 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width