Title: [Bug]: Different behaviour between showing and savefig PDF · Issue #31585 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Different behaviour between showing and savefig PDF · Issue #31585 · matplotlib/matplotlib
X Title: [Bug]: Different behaviour between showing and savefig PDF · Issue #31585 · matplotlib/matplotlib
Description: Bug summary Hi there, I came across an error that was tricky to debug, as it had some unexpected behaviour. Basically, I used ls="" in a scatter plot, which rise an issue if i understand it correctly. But when plt.show(), the image is di...
Open Graph Description: Bug summary Hi there, I came across an error that was tricky to debug, as it had some unexpected behaviour. Basically, I used ls="" in a scatter plot, which rise an issue if i understand it correct...
X Description: Bug summary Hi there, I came across an error that was tricky to debug, as it had some unexpected behaviour. Basically, I used ls="" in a scatter plot, which rise an issue if i understand ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31585
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Different behaviour between showing and savefig PDF","articleBody":"### Bug summary\n\nHi there, \nI came across an error that was tricky to debug, as it had some unexpected behaviour. Basically, I used ls=\"\" in a scatter plot, which rise an issue if i understand it correctly. But when plt.show(), the image is displayed perfectly, while plt.savefig for PDF specifically crashes with the unreadable error below (`ValueError: zero-size array to reduction operation maximum which has no identity`).\n\nYou can find the minimum example below. Please uncomment plt.show() for no error.\n\n### Code for reproduction\n\n```Python\nplt.figure()\nplt.scatter([0, 1], [0, 1], ls=\"\")\n#plt.show()\nplt.savefig(\"test.pdf\")\n```\n\n### Actual outcome\n\n```\nTraceback (most recent call last):\n File \"\u003cuser_script\u003e.py\", line \u003cline_number\u003e, in \u003cmodule\u003e\n \u003cuser_function\u003e()\n File \"\u003cuser_script\u003e.py\", line \u003cline_number\u003e, in \u003cuser_function\u003e\n plt.savefig(\"\u003coutput_file\u003e.pdf\")\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/pyplot.py\", line 1228, in savefig\n res = fig.savefig(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/figure.py\", line 3395, in savefig\n self.canvas.print_figure(fname, **kwargs)\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/backend_bases.py\", line 2204, in print_figure\n result = print_method(\n ^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/backend_bases.py\", line 2054, in \u003clambda\u003e\n print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(\n ^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/backends/backend_pdf.py\", line 2799, in print_pdf\n self.figure.draw(renderer)\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/artist.py\", line 95, in draw_wrapper\n result = draw(artist, renderer, *args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/artist.py\", line 72, in draw_wrapper\n return draw(artist, renderer)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/figure.py\", line 3162, in draw\n mimage._draw_list_compositing_images(\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/image.py\", line 132, in _draw_list_compositing_images\n a.draw(renderer)\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/artist.py\", line 72, in draw_wrapper\n return draw(artist, renderer)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/axes/_base.py\", line 3137, in draw\n mimage._draw_list_compositing_images(\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/image.py\", line 132, in _draw_list_compositing_images\n a.draw(renderer)\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/artist.py\", line 72, in draw_wrapper\n return draw(artist, renderer)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/collections.py\", line 1005, in draw\n super().draw(renderer)\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/artist.py\", line 72, in draw_wrapper\n return draw(artist, renderer)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/collections.py\", line 426, in draw\n renderer.draw_path_collection(\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/matplotlib/backends/backend_pdf.py\", line 2074, in draw_path_collection\n padding = np.max(linewidths)\n ^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/numpy/core/fromnumeric.py\", line 2810, in max\n return _wrapreduction(a, np.maximum, 'max', axis, None, out,\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"\u003cpython_env\u003e/lib/python3.11/site-packages/numpy/core/fromnumeric.py\", line 88, in _wrapreduction\n return ufunc.reduce(obj, axis, dtype, out, **passkwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nValueError: zero-size array to reduction operation maximum which has no identity\n```\n\n### Expected outcome\n\nThe error should be on the use of lw=\"\" in the scatter plot, but it should be coherent with the plt.show (which is not the case at the moment)\n\n### Additional information\n\nI don't know where the bug comes from, but I assume that \"ls\" is defined as a parameter of scatter, but is not uniformely treated in between the interactive window and the pdf backend.\n\n### Operating system\n\nMacOS 14.8.2, M1 pro processor.\n\n### Matplotlib Version\n\n3.9.2\n\n### Matplotlib Backend\n\nmacosx\n\n### Python version\n\n3.11.10\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nconda","author":{"url":"https://github.com/Nebulean","@type":"Person","name":"Nebulean"},"datePublished":"2026-04-29T12:17:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/31585/matplotlib/issues/31585"}
| 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:35b51549-264a-3b7b-1174-075d1741343f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D36A:141904:140344:1A8939:6A5162A2 |
| html-safe-nonce | e873d4b5d5a81c60d275dca220038a24f7560397103d160cfd313979abb7be44 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzZBOjE0MTkwNDoxNDAzNDQ6MUE4OTM5OjZBNTE2MkEyIiwidmlzaXRvcl9pZCI6IjQxMzY0OTk5Njk2ODIxMzc3NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1abcf475bf53f9fc76f164d8a2928888232db5765cc29c3e0565ec86b20ad25a |
| hovercard-subject-tag | issue:4350455686 |
| 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/31585/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd0500eb5223c126f54680bfbe631c16322147c1b89a5f195e17b247eb3900d0/matplotlib/matplotlib/issues/31585 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd0500eb5223c126f54680bfbe631c16322147c1b89a5f195e17b247eb3900d0/matplotlib/matplotlib/issues/31585 |
| og:image:alt | Bug summary Hi there, I came across an error that was tricky to debug, as it had some unexpected behaviour. Basically, I used ls="" in a scatter plot, which rise an issue if i understand it correct... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Nebulean |
| 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 | 2eeb434949a926fad21064b4d395a54759f7a0b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width