Title: [Bug]: ValueError ("cannot convert float NaN to integer") when trying to show horizontally-stacked subplots · Issue #31881 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: ValueError ("cannot convert float NaN to integer") when trying to show horizontally-stacked subplots · Issue #31881 · matplotlib/matplotlib
X Title: [Bug]: ValueError ("cannot convert float NaN to integer") when trying to show horizontally-stacked subplots · Issue #31881 · matplotlib/matplotlib
Description: Bug summary Showing two horizontally-stacked subplots with a shared y axis and per-subplot titles fails if the y values are too large. This is a regression in matplotlib 3.11.0; it worked in 3.10.9. Code for reproduction fig, axes = plt....
Open Graph Description: Bug summary Showing two horizontally-stacked subplots with a shared y axis and per-subplot titles fails if the y values are too large. This is a regression in matplotlib 3.11.0; it worked in 3.10.9...
X Description: Bug summary Showing two horizontally-stacked subplots with a shared y axis and per-subplot titles fails if the y values are too large. This is a regression in matplotlib 3.11.0; it worked in 3.10.9...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31881
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: ValueError (\"cannot convert float NaN to integer\") when trying to show horizontally-stacked subplots","articleBody":"### Bug summary\n\nShowing two horizontally-stacked subplots with a shared y axis and per-subplot titles fails if the y values are too large. This is a regression in matplotlib 3.11.0; it worked in 3.10.9.\n\n### Code for reproduction\n\n```Python\nfig, axes = plt.subplots(1,2, figsize=(12,5), sharey=True, tight_layout=True)\n\nx = list(range(10))\ny = [1e53 for _ in x]\n\nfor i, ax in enumerate(axes):\n ax.set_title(f'Subplot {i}')\n ax.plot(x,y)\n\nplt.show()\n```\n\n### Actual outcome\n\n```\nTraceback (most recent call last):\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/backend_bases.py\", line 1165, in _on_timer\n ret = func(*args, **kwargs)\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/backends/backend_macosx.py\", line 71, in callback_func\n callback()\n ~~~~~~~~^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/backends/backend_macosx.py\", line 93, in _draw_idle\n self.draw()\n ~~~~~~~~~^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/backends/backend_macosx.py\", line 56, in draw\n super().draw()\n ~~~~~~~~~~~~^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/backends/backend_agg.py\", line 438, in draw\n self.figure.draw(self.renderer)\n ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/artist.py\", line 94, in draw_wrapper\n result = draw(artist, renderer, *args, **kwargs)\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/artist.py\", line 71, in draw_wrapper\n return draw(artist, renderer)\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/figure.py\", line 3282, in draw\n mimage._draw_list_compositing_images(\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^\n renderer, self, artists, self.suppressComposite)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/image.py\", line 133, in _draw_list_compositing_images\n a.draw(renderer)\n ~~~~~~^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/artist.py\", line 71, in draw_wrapper\n return draw(artist, renderer)\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axes/_base.py\", line 3314, in draw\n self._update_title_position(renderer)\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axes/_base.py\", line 3258, in _update_title_position\n ax.yaxis.get_tightbbox(renderer) # update offsetText\n ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axis.py\", line 1425, in get_tightbbox\n ticks_to_draw = self._update_ticks()\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axis.py\", line 1344, in _update_ticks\n major_locs = self.get_majorticklocs()\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axis.py\", line 1673, in get_majorticklocs\n return self.major.locator()\n ~~~~~~~~~~~~~~~~~~^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/ticker.py\", line 2299, in __call__\n return self.tick_values(vmin, vmax)\n ~~~~~~~~~~~~~~~~^^^^^^^^^^^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/ticker.py\", line 2307, in tick_values\n locs = self._raw_ticks(vmin, vmax)\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/ticker.py\", line 2237, in _raw_ticks\n nbins = np.clip(self.axis.get_tick_space(),\n ~~~~~~~~~~~~~~~~~~~~~~~~^^\n File \"/opt/miniconda3/envs/snewpy/lib/python3.13/site-packages/matplotlib/axis.py\", line 2984, in get_tick_space\n return int(np.floor(length / size))\nValueError: cannot convert float NaN to integer\n```\n\n### Expected outcome\n\nA plot with two (very boring) subplots; as in the following example generated with matplotlib 3.10.9:\n\u003cimg width=\"1312\" height=\"676\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/991d0bdd-8764-4a7e-bcc4-71290873c964\" /\u003e\n\n### Additional information\n\nThe bug only seems to happen if three factors come together:\n* `y` becomes large enough to require scientific notation, with the `1e53` part shown at the top of the y axis. (When changing the code to `y = [1e2 for _ in x]`, the error disappears.)\n* A title is set for `axes[1]`. (When changing the code to `if i ==0: ax.set_title(f\"Subplot {i}\")`, the error disappears.)\n* The subplots are initialised with `sharey=True`. (When changing it to `False`, the error disappears.)\n\nThe same code has worked correctly in matplotlib 3.10.9 and earlier. (See “Expected Outcome” section.)\nI was also able to reproduce this bug on Ubuntu 24.04 in GitHub CI.\n\n### Operating system\n\nmacOS 15.7.7\n\n### Matplotlib Version\n\n3.11.0\n\n### Matplotlib Backend\n\nmacosx\n\n### Python version\n\n3.13.2\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/JostMigenda","@type":"Person","name":"JostMigenda"},"datePublished":"2026-06-12T18:57:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/31881/matplotlib/issues/31881"}
| 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:8cebea64-747d-37b2-2595-31be777e193f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0B6:238A8C:61584:85069:6A5232F7 |
| html-safe-nonce | 7804621eadc1454257ebc218dce9e68f4e3ad135815f2290026cdfe1616ecede |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEI2OjIzOEE4Qzo2MTU4NDo4NTA2OTo2QTUyMzJGNyIsInZpc2l0b3JfaWQiOiI4MTE1MjE3NjI2Njk3OTcwNDIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8b10e90d799200d3816307d8ffb5b2e55ceee4c68b00e153ff83944d8f158413 |
| hovercard-subject-tag | issue:4651825981 |
| 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/31881/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed5cd904bc643e7979a1145974f87db36c8ec959c19b7f1f100351d6a009fc1b/matplotlib/matplotlib/issues/31881 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed5cd904bc643e7979a1145974f87db36c8ec959c19b7f1f100351d6a009fc1b/matplotlib/matplotlib/issues/31881 |
| og:image:alt | Bug summary Showing two horizontally-stacked subplots with a shared y axis and per-subplot titles fails if the y values are too large. This is a regression in matplotlib 3.11.0; it worked in 3.10.9... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JostMigenda |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width