Title: [Bug]: Error using width_ratios with nested mosaic in subplot_mosaic() · Issue #24099 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Error using width_ratios with nested mosaic in subplot_mosaic() · Issue #24099 · matplotlib/matplotlib
X Title: [Bug]: Error using width_ratios with nested mosaic in subplot_mosaic() · Issue #24099 · matplotlib/matplotlib
Description: Bug summary plt.subplot_mosaic() fails with a confusing error message when passing width_ratios (or height_ratios) with a nested list mosaic, unless all outer and inner mosaics have the same number of columns (or rows). Code for reproduc...
Open Graph Description: Bug summary plt.subplot_mosaic() fails with a confusing error message when passing width_ratios (or height_ratios) with a nested list mosaic, unless all outer and inner mosaics have the same number...
X Description: Bug summary plt.subplot_mosaic() fails with a confusing error message when passing width_ratios (or height_ratios) with a nested list mosaic, unless all outer and inner mosaics have the same number...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24099
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Error using width_ratios with nested mosaic in subplot_mosaic()","articleBody":"### Bug summary\r\n\r\nplt.subplot_mosaic() fails with a confusing error message when passing width_ratios (or height_ratios) with a nested list mosaic, unless all outer and inner mosaics have the same number of columns (or rows).\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\nmosaic = [[\"A\", [[\"B\"],\r\n [\"C\"]]]]\r\n\r\nfig, axd = plt.subplot_mosaic(mosaic, width_ratios=[2, 1])\r\n```\r\n\r\n\r\n### Actual outcome\r\n```\r\nTraceback (most recent call last):\r\n File \"C:\\Users\\bneary3\\test_layouts.py\", line 6, in \u003cmodule\u003e\r\n fig, axd = plt.subplot_mosaic(mosaic, width_ratios=[2, 1])\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\pyplot.py\", line 1533, in subplot_mosaic\r\n ax_dict = fig.subplot_mosaic(\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\figure.py\", line 2042, in subplot_mosaic\r\n ret = _do_layout(gs, mosaic, *_identify_keys_and_nested(mosaic))\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\figure.py\", line 2023, in _do_layout\r\n gs[j, k].subgridspec(rows, cols, **gridspec_kw),\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\gridspec.py\", line 749, in subgridspec\r\n return GridSpecFromSubplotSpec(nrows, ncols, self, **kwargs)\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\gridspec.py\", line 516, in __init__\r\n super().__init__(nrows, ncols,\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\gridspec.py\", line 56, in __init__\r\n self.set_width_ratios(width_ratios)\r\n File \"C:\\Users\\bneary3\\Anaconda3\\envs\\mpl36\\lib\\site-packages\\matplotlib\\gridspec.py\", line 111, in set_width_ratios\r\n raise ValueError('Expected the given number of width ratios to '\r\nValueError: Expected the given number of width ratios to match the number of columns of the grid\r\n```\r\n### Expected outcome\r\n\r\n\r\n\r\n### Additional information\r\n\r\nFrom what I can tell, this happens because the layout is built recursively, passing the same gridspec_kw to subgridspec() at each level of nesting. I realize that the use of width_ratios / height_ratios / gridspec_kw with nested list mosaics could get complicated, but it would be nice to be able to at least specify them for the outer list, or in some other way implement this feature for nested list layouts. If not, maybe include a helpful error message that explains this limitation so the user doesn't think they have specified the wrong number of ratios.\r\n\r\n### Operating system\r\n\r\nWindows 10\r\n\r\n### Matplotlib Version\r\n\r\n3.6.0\r\n\r\n### Matplotlib Backend\r\n\r\nQtAgg\r\n\r\n### Python version\r\n\r\n3.10\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/bneary3","@type":"Person","name":"bneary3"},"datePublished":"2022-10-05T20:18:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/24099/matplotlib/issues/24099"}
| 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:22499a29-9492-0334-77fb-fc45d1b6fbf6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8352:272A73:D17BFA:1197D08:6A51696A |
| html-safe-nonce | 30bbf9e6b04bd848e8edd8d13d283486a47ac4c12d3b257e6528fb0793806afb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzUyOjI3MkE3MzpEMTdCRkE6MTE5N0QwODo2QTUxNjk2QSIsInZpc2l0b3JfaWQiOiIzODAyNTE5NjQwNTQ4MTQxNDE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3a833b7f50f9edd8c7f7cc3d27934e6d2132319b3ba777a464c9482a7355bbdc |
| hovercard-subject-tag | issue:1398330069 |
| 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/24099/issue_layout |
| twitter:image | https://opengraph.githubassets.com/49115734c80768310011fbfaf201340ce05ec75f296f5932cd53bd1188e70370/matplotlib/matplotlib/issues/24099 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/49115734c80768310011fbfaf201340ce05ec75f296f5932cd53bd1188e70370/matplotlib/matplotlib/issues/24099 |
| og:image:alt | Bug summary plt.subplot_mosaic() fails with a confusing error message when passing width_ratios (or height_ratios) with a nested list mosaic, unless all outer and inner mosaics have the same number... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bneary3 |
| 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 | 60eaaf6d4dbaa817031b556aebd8a0a7eeb81b97 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width