Title: SubFigure hspace=None incorrectly applies default vertical spacing when wspace is specified · Issue #32076 · matplotlib/matplotlib · GitHub
Open Graph Title: SubFigure hspace=None incorrectly applies default vertical spacing when wspace is specified · Issue #32076 · matplotlib/matplotlib
X Title: SubFigure hspace=None incorrectly applies default vertical spacing when wspace is specified · Issue #32076 · matplotlib/matplotlib
Description: Bug summary SubFigure with hspace=None incorrectly applies the default vertical spacing when wspace is specified. This produces an unintended vertical gap between subfigures. Code for reproduction import matplotlib matplotlib.use("Agg") ...
Open Graph Description: Bug summary SubFigure with hspace=None incorrectly applies the default vertical spacing when wspace is specified. This produces an unintended vertical gap between subfigures. Code for reproduction ...
X Description: Bug summary SubFigure with hspace=None incorrectly applies the default vertical spacing when wspace is specified. This produces an unintended vertical gap between subfigures. Code for reproduction ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32076
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SubFigure hspace=None incorrectly applies default vertical spacing when wspace is specified","articleBody":"### Bug summary\n\n`SubFigure` with `hspace=None` incorrectly applies the default vertical spacing when `wspace` is specified. This produces an unintended vertical gap between subfigures.\n\n### Code for reproduction\n\n```python\nimport matplotlib\nmatplotlib.use(\"Agg\")\nimport matplotlib.pyplot as plt\n\nfig = plt.figure(figsize=(6, 4))\nwspace, hspace = 0.2, None\nprint(\"Input: wspace=\", wspace, \"hspace=None\")\nsubfigures = fig.subfigures(nrows=2, ncols=2,\n wspace=wspace, hspace=hspace)\n\nfor row in range(2):\n for column in range(2):\n subfigures[row, column].add_subplot().plot([0, 1], [0, 1])\n\nfig.canvas.draw()\nfor row in range(2):\n for column in range(2):\n print(f\"Subfigure ({row}, {column}) bounds:\",\n tuple(round(value, 3)\n for value in subfigures[row, column].bbox.bounds))\nplt.close(fig)\n```\n\n### Actual outcome\n\n```text\nInput: wspace= 0.2 hspace=None\nSubfigure (0, 0) bounds: (np.float64(0.0), np.float64(218.182), np.float64(272.727), np.float64(181.818))\nSubfigure (0, 1) bounds: (np.float64(327.273), np.float64(218.182), np.float64(272.727), np.float64(181.818))\nSubfigure (1, 0) bounds: (np.float64(0.0), np.float64(0.0), np.float64(272.727), np.float64(181.818))\nSubfigure (1, 1) bounds: (np.float64(327.273), np.float64(0.0), np.float64(272.727), np.float64(181.818))\n```\n\n### Expected outcome\n\n```text\nInput: wspace= 0.2 hspace=None\nSubfigure (0, 0) bounds: (0.0, 200.0, 300.0, 200.0)\nSubfigure (0, 1) bounds: (300.0, 200.0, 300.0, 200.0)\nSubfigure (1, 0) bounds: (0.0, 0.0, 300.0, 200.0)\nSubfigure (1, 1) bounds: (300.0, 0.0, 300.0, 200.0)\n```\n\nWhen no layout engine is active, `hspace=None` should result in no vertical spacing, while the requested `wspace=0.2` should be applied.\n\n### Additional information\n\nThis is a regression introduced by [PR #25960](https://github.com/matplotlib/matplotlib/pull/25960).\n\nThe example uses only public Matplotlib APIs and legal inputs, and its output is deterministic. The horizontal spacing is applied as requested, but `hspace=None` produces a vertical gap: the subfigure heights are 181.818 pixels with a 36.364-pixel gap. According to the updated documentation and the intent of PR #25960, unspecified spacing should be zero when no layout engine is active.\n\nPassing `hspace=None` through `GridSpec` appears to fall back to the figure's default subplot `hspace`, causing unintended vertical spacing when only `wspace` is specified. The analogous issue may occur when only `hspace` is specified.\n\n### Operating system\n\nLinux\n\n### Matplotlib Version\n\n3.11.1\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.11.13\n\n### Jupyter version\n\nN/A\n\n### Installation\n\nN/A","author":{"url":"https://github.com/SuYanqi","@type":"Person","name":"SuYanqi"},"datePublished":"2026-07-20T09:55:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/32076/matplotlib/issues/32076"}
| 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:6b220c21-06b1-f7f7-830e-9b25823be2ec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D658:E4D2D:F6BB9:15AD14:6A62E8E1 |
| html-safe-nonce | b4fc7f91a50b31781e37c538b645dbca1f32f3d7babb5f380ebc90f6f16e0239 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjU4OkU0RDJEOkY2QkI5OjE1QUQxNDo2QTYyRThFMSIsInZpc2l0b3JfaWQiOiIxNTc3NzA0MTU2MDgwOTY5OTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 61e8827de817f1f4df9c81cca104d9992416a791158025f8e9461a6858980556 |
| hovercard-subject-tag | issue:4927807773 |
| 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/32076/issue_layout |
| twitter:image | https://opengraph.githubassets.com/33005faeb9b069b8ff5e6495cfda05c5f1146eb3a4b5e10d296a3d737bd7b59e/matplotlib/matplotlib/issues/32076 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/33005faeb9b069b8ff5e6495cfda05c5f1146eb3a4b5e10d296a3d737bd7b59e/matplotlib/matplotlib/issues/32076 |
| og:image:alt | Bug summary SubFigure with hspace=None incorrectly applies the default vertical spacing when wspace is specified. This produces an unintended vertical gap between subfigures. Code for reproduction ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SuYanqi |
| hostname | github.com |
| expected-hostname | github.com |
| None | df33b1b61ee7b9a0af988199bfc3503c9c1acafb1f1d40e1f140ea7c84f890dd |
| 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 | d41cd1bdb290013455c0ac430fa755621733f5eb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width