Title: constrained-layout gives wrong results when explicitly equal width ratios are set · Issue #17304 · matplotlib/matplotlib · GitHub
Open Graph Title: constrained-layout gives wrong results when explicitly equal width ratios are set · Issue #17304 · matplotlib/matplotlib
X Title: constrained-layout gives wrong results when explicitly equal width ratios are set · Issue #17304 · matplotlib/matplotlib
Description: Bug report Bug summary When passing width_ratios = [1, 1, 1] instead of not passing it at all (which should be synonymous), constrained_layout sometimes gives incorrect results. Code for reproduction import matplotlib as mpl from matplot...
Open Graph Description: Bug report Bug summary When passing width_ratios = [1, 1, 1] instead of not passing it at all (which should be synonymous), constrained_layout sometimes gives incorrect results. Code for reproducti...
X Description: Bug report Bug summary When passing width_ratios = [1, 1, 1] instead of not passing it at all (which should be synonymous), constrained_layout sometimes gives incorrect results. Code for reproducti...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/17304
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"constrained-layout gives wrong results when explicitly equal width ratios are set","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nWhen passing `width_ratios = [1, 1, 1]` instead of not passing it at all (which should be synonymous), constrained_layout sometimes gives incorrect results.\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n```python\r\nimport matplotlib as mpl\r\nfrom matplotlib import pyplot as plt, gridspec, testing\r\n\r\nmpl.rcdefaults()\r\nmpl.style.use([\"classic\", \"_classic_test_patch\"])\r\nmpl.testing.set_font_settings_for_testing()\r\n\r\ndef example_plot(ax, fontsize=12):\r\n ax.plot([1, 2])\r\n ax.locator_params(nbins=3)\r\n ax.set_xlabel('x-label', fontsize=fontsize)\r\n ax.set_ylabel('y-label', fontsize=fontsize)\r\n ax.set_title('Title', fontsize=fontsize)\r\n\r\nfig = plt.figure(constrained_layout=True)\r\ngs = gridspec.GridSpec(3, 3, figure=fig)\r\n\r\nax1 = fig.add_subplot(gs[0, 0])\r\nax2 = fig.add_subplot(gs[0, 1:])\r\nax3 = fig.add_subplot(gs[1:, 0:2])\r\nax4 = fig.add_subplot(gs[1:, -1])\r\n\r\nfor ax in fig.axes:\r\n example_plot(ax)\r\n\r\nfig.savefig(\"/tmp/cl1.png\")\r\n\r\nfig = plt.figure(constrained_layout=True)\r\ngs = gridspec.GridSpec(3, 3, figure=fig,\r\n width_ratios=[1, 1, 1], height_ratios=[1, 1, 1])\r\n\r\nax1 = fig.add_subplot(gs[0, 0])\r\nax2 = fig.add_subplot(gs[0, 1:])\r\nax3 = fig.add_subplot(gs[1:, 0:2])\r\nax4 = fig.add_subplot(gs[1:, -1])\r\n\r\nfor ax in fig.axes:\r\n example_plot(ax)\r\n\r\nfig.savefig(\"/tmp/cl2.png\")\r\n\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\ncl1.png\r\n\r\n\r\ncl2.png\r\n\r\n\r\nClearly in cl2.png the widths are not in the ratios 1:1:1 but (approximately) 1:2:1.\r\n\r\nThis is likely a floating point error; it is extremely sensitive to conditions, in particular the call to `set_font_settings_for_reproducibility` (which just sets some font-related rcs) is necessary to observe this.\r\n\r\n**Expected outcome**\r\n\r\ntwice the same image\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: archlinux\r\n * Matplotlib version: master\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): agg\r\n * Python version: 38\r\n * Jupyter version (if applicable): no\r\n * Other libraries: \r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2020-05-02T15:23:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/17304/matplotlib/issues/17304"}
| 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:00e531d3-be12-d1b4-1c0c-73dbd39d8116 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E402:19C73D:34437D1:46FEFD8:6A53EBCB |
| html-safe-nonce | 4f566cc5412cc10f8a44c5ae1811facc830acf236df7537d2ec9ecbf7d220fa7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDAyOjE5QzczRDozNDQzN0QxOjQ2RkVGRDg6NkE1M0VCQ0IiLCJ2aXNpdG9yX2lkIjoiODYzNjAxMTg3NDgxMzczMzgzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fb4a1655be8f79a8f633d8161f1be466c01cf75e0c6a3a966160b3ceb83af596 |
| hovercard-subject-tag | issue:611212651 |
| 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/17304/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cbaf800811585a0ab0689dc52a72ae588ff8fa3fe72ca7591e6356cb1251aa5e/matplotlib/matplotlib/issues/17304 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cbaf800811585a0ab0689dc52a72ae588ff8fa3fe72ca7591e6356cb1251aa5e/matplotlib/matplotlib/issues/17304 |
| og:image:alt | Bug report Bug summary When passing width_ratios = [1, 1, 1] instead of not passing it at all (which should be synonymous), constrained_layout sometimes gives incorrect results. Code for reproducti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| 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