Title: [Bug]: savefig to PNG raises 'failed to load glyph' for small text in macOS Helvetica (Regular) with matplotlib 3.11.0 and 3.11.2 · Issue #32650 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: savefig to PNG raises 'failed to load glyph' for small text in macOS Helvetica (Regular) with matplotlib 3.11.0 and 3.11.2 · Issue #32650 · matplotlib/matplotlib
X Title: [Bug]: savefig to PNG raises 'failed to load glyph' for small text in macOS Helvetica (Regular) with matplotlib 3.11.0 and 3.11.2 · Issue #32650 · matplotlib/matplotlib
Description: Bug summary With matplotlib 3.11.0 and 3.11.2 and default rcParams, saving a figure to PNG raises RuntimeError: failed to load glyph when it has text in the regular face of macOS's Helvetica at 7 pixels per em or fewer, such as 5 pt text...
Open Graph Description: Bug summary With matplotlib 3.11.0 and 3.11.2 and default rcParams, saving a figure to PNG raises RuntimeError: failed to load glyph when it has text in the regular face of macOS's Helvetica at 7 p...
X Description: Bug summary With matplotlib 3.11.0 and 3.11.2 and default rcParams, saving a figure to PNG raises RuntimeError: failed to load glyph when it has text in the regular face of macOS's Helvetica at...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32650
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: savefig to PNG raises 'failed to load glyph' for small text in macOS Helvetica (Regular) with matplotlib 3.11.0 and 3.11.2","articleBody":"### Bug summary\n\nWith matplotlib 3.11.0 and 3.11.2 and default rcParams, saving a figure to PNG raises `RuntimeError: failed to load glyph` when it has text in the regular face of macOS's Helvetica at 7 pixels per em or fewer, such as 5 pt text at 72 dpi. matplotlib 3.10.9 saves the same figure. With 3.11.2, saving it as PDF, SVG, PS or EPS works.\n\n### Code for reproduction\n\n```Python\n# macOS only: 'Helvetica' must resolve to /System/Library/Fonts/Helvetica.ttc\nimport matplotlib\nmatplotlib.use(\"Agg\")\nimport matplotlib.pyplot as plt\n\nfig = plt.figure(figsize=(2, 1))\nfig.text(0.1, 0.5, \"yield\", fontfamily=\"Helvetica\", fontsize=5)\nfig.savefig(\"out.png\", dpi=72)\n```\n\n### Actual outcome\n\n```\nTraceback (most recent call last):\n File \"/Users/runner/work/depictr-py/depictr-py/diag/report_snippet.py\", line 7, in \u003cmodule>\n fig.savefig(\"out.png\", dpi=72)\n ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/figure.py\", line 3515, in savefig\n self.canvas.print_figure(fname, **kwargs)\n ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/backend_bases.py\", line 2289, in print_figure\n result = print_method(\n filename,\n ...\u003c3 lines>...\n bbox_inches_restore=_bbox_inches_restore,\n **kwargs)\n File \".../site-packages/matplotlib/backend_bases.py\", line 2146, in \u003clambda>\n print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(\n ~~~~^\n *args, **{k: v for k, v in kwargs.items() if k not in skip}))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/backends/backend_agg.py\", line 537, in print_png\n self._print_pil(filename_or_obj, \"png\", pil_kwargs, metadata)\n ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/backends/backend_agg.py\", line 485, in _print_pil\n FigureCanvasAgg.draw(self)\n ~~~~~~~~~~~~~~~~~~~~^^^^^^\n File \".../site-packages/matplotlib/backends/backend_agg.py\", line 438, in draw\n self.figure.draw(self.renderer)\n ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/artist.py\", line 94, in draw_wrapper\n result = draw(artist, renderer, *args, **kwargs)\n File \".../site-packages/matplotlib/artist.py\", line 71, in draw_wrapper\n return draw(artist, renderer)\n File \".../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 \".../site-packages/matplotlib/image.py\", line 133, in _draw_list_compositing_images\n a.draw(renderer)\n ~~~~~~^^^^^^^^^^\n File \".../site-packages/matplotlib/artist.py\", line 71, in draw_wrapper\n return draw(artist, renderer)\n File \".../site-packages/matplotlib/text.py\", line 853, in draw\n bbox, info, _ = self._get_layout(renderer)\n ~~~~~~~~~~~~~~~~^^^^^^^^^^\n File \".../site-packages/matplotlib/text.py\", line 479, in _get_layout\n w, h, d = _get_text_metrics_with_cache(\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^\n renderer, clean_line, self._fontproperties,\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n ismath=ismath, dpi=self.get_figure(root=True).dpi)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/text.py\", line 59, in _get_text_metrics_with_cache\n return get_text_metrics(text, fontprop.copy(), ismath, dpi)\n File \".../site-packages/matplotlib/text.py\", line 125, in _text_metrics\n return local_renderer.get_text_width_height_descent(text, fontprop, ismath)\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^\n File \".../site-packages/matplotlib/backends/backend_agg.py\", line 263, in get_text_width_height_descent\n font.set_text(s, 0.0, flags=get_hinting_flag())\n ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: failed to load glyph\n```\n\n(3.11.2 on macOS 26.7.2. `...` stands for `/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13`.)\n\n### Expected outcome\n\nThe figure is saved, as it is with 3.10.9.\n\n### Additional information\n\n`FT2Font.load_glyph` on the same face, size and flags reports the FreeType error that `set_text` leaves out of its message (src/ft2font.cpp lines 477 to 479 in 3.11.2):\n\n```python\nfrom matplotlib.ft2font import FT2Font, LoadFlags\n\nfont = FT2Font(\"/System/Library/Fonts/Helvetica.ttc\")\nfont.set_size(5, 72)\nfont.load_glyph(font.get_char_index(ord(\"y\")), flags=LoadFlags.DEFAULT)\n# RuntimeError: FT_Load_Glyph (ft2font.cpp line 646) failed with error 0x85: division by zero\n```\n\nThe error appears only with the font's native hinter (`LoadFlags.DEFAULT` or `NO_AUTOHINT`), only in face 0 of the six faces in Helvetica.ttc and only at 7 px/em or fewer (whole sizes from 1 to 15 tested). FreeType 2.14.3 is the copy bundled with 3.11.0 and 3.11.2. FreeType 2.6.1 (the copy in 3.10.9, with `FT2Font(path, hinting_factor=1)`), 2.13.2 and 2.15.0 (both called through ctypes) return the same error, and they load the glyph when the horizontal resolution is 8 times the vertical one, as 3.10.9's default `hinting_factor` of 8 made it. So the font's own hinting instructions appear to fail at these sizes in every FreeType version tried. 3.10.9's defaults did not run them at these sizes: its `text.hinting` default was 'force_autohint', and its hinting factor raised the horizontal resolution. 3.11 changed the `text.hinting` default to 'default' (#29816) and dropped the hinting factor (#31521). I could not find the `text.hinting` change in the 3.11.0 API changes.\n\nAs a workaround, setting `plt.rcParams[\"text.hinting\"]` to `\"force_autohint\"` or `\"no_hinting\"` saves the figure with 3.11.0 and 3.11.2. A downstream project, Tavotto, hit the same error with matplotlib 3.11.2 and now retries a failing call with `text.hinting` set to `\"no_hinting\"` (Tavotto/Tavotto#1872). This differs from #32063, where text in fonts with embedded bitmap strikes comes out blank: here the figure is not saved at all.\n\nTwo changes may be worth considering. One is, when `FT_Load_Glyph` fails with hinting enabled, to lay out and load the text again without hinting or with the auto-hinter, with a warning, because `FT2Font::layout` passes the same load flags to raqm (src/ft2font.cpp line 328). The other is to mention the new `text.hinting` default in the 3.11 API changes. On main, #32120 loads these glyphs through `FT_CHECK`, so the message will name FreeType's error from 3.12. The hinting default and the load flags are unchanged there, so I expect the same failure, although I have not run main.\n\nTested on GitHub Actions runners with macOS 15.8.2 and 26.7.2 (arm64), Python 3.13.17 and wheels from PyPI. Scripts: https://github.com/pablobernabeu/depictr-py/tree/61ad513081f9000392838bd7e975e5232b5c3864/diag. Logs: [mpl_only.py](https://github.com/pablobernabeu/depictr-py/actions/runs/43752353059), [ft_versions.py](https://github.com/pablobernabeu/depictr-py/actions/runs/43752929088), [hinting_factor.py](https://github.com/pablobernabeu/depictr-py/actions/runs/43753177369), [the snippets above](https://github.com/pablobernabeu/depictr-py/actions/runs/43753483025) and [font_info.py](https://github.com/pablobernabeu/depictr-py/actions/runs/43754764722). I found it through plotnine, whose default theme lists Helvetica first among its sans-serif fonts.\n\n### Operating system\n\nmacOS 15.8.2 and macOS 26.7.2 (arm64)\n\n### Matplotlib Version\n\n3.11.2 and 3.11.0 (3.11.1 not tested). 3.10.9 is not affected.\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.13.17\n\n### Jupyter version\n\nNot used\n\n### Installation\n\npip","author":{"url":"https://github.com/pablobernabeu","@type":"Person","name":"pablobernabeu"},"datePublished":"2026-11-22T23:26:56Z","url":"https://github.com/matplotlib/matplotlib/issues/32650"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:74990dbf-0580-255e-7f6f-1548e7be22e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D870:3CDC55:94E552:C7D3AF:6B064EDF |
| html-safe-nonce | c5edefca3d47915a5be1973b6d92219be85c32932c240050626ae695c7636797 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODcwOjNDREM1NTo5NEU1NTI6QzdEM0FGOjZCMDY0RURGIiwidmlzaXRvcl9pZCI6IjgzNzgzMjMxNDQyNTk1NTUwMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 17b958634a6873a3f6d62715c3a4402cea2cda6a075bce1439ac8746817c8e4f |
| hovercard-subject-tag | issue:6549196325 |
| 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/32650/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c639436ba2509b3de0aecd03dd9ba5a82091ee7789229e0b96085fc2c684d265/matplotlib/matplotlib/issues/32650 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c639436ba2509b3de0aecd03dd9ba5a82091ee7789229e0b96085fc2c684d265/matplotlib/matplotlib/issues/32650 |
| og:image:alt | Bug summary With matplotlib 3.11.0 and 3.11.2 and default rcParams, saving a figure to PNG raises RuntimeError: failed to load glyph when it has text in the regular face of macOS's Helvetica at 7 p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pablobernabeu |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| 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 | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width