New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: savefig triggers ValueError with scatter #28123
Comments
If you are expecting a line between your points, then What it is actually controlling, though, is the lines of the markers themselves. This is actually done through Now, given that that is what you want, In Line2D, the various forms of "linestyle for not having the line" are normalized to matplotlib/lib/matplotlib/lines.py Lines 1170 to 1171 in 8fb842c
(And then handled within Line2D specific code to not draw anything...) And In fact if you pass A quick way to get the desired effect would be to use Anyway, the Collection matplotlib/lib/matplotlib/collections.py Lines 591 to 631 in 8fb842c
The matplotlib/lib/matplotlib/lines.py Line 39 in 8fb842c
But it does not handle all of the aliases ("", " ", etc). And arguably can't... since "not drawing" is different than "what is the offset and dashpattern for the thing I should draw?" Now, one other wrinkle here is that when given matplotlib/lib/matplotlib/collections.py Lines 617 to 624 in 8fb842c
The last wrinkle is how it is treated by backends, as agg-based renderers seem to be okay with that? (I think it may actually be failing to draw the collection at all, possibly due to a Docs wise, the "None" case, which appears in the Proposed solution:
TL;DR:
|
Thank you for the thorough and quick response! I'm aware that it really doesn't make sense to pass a The reason I think it qualifies as a bug is maybe more the cryptic error message that is thrown, specifically when saving as a pdf, when saving as png and I think it would be a perfectly reasonable fix to just throw an error if |
Make Collection.set_linestyle normalize the empty string to 'None', and make Collection._bcast_lwls force linewidths to 0 if the dashes on_off_seq is None.
Bug summary
Creating a scatterplot with
scatter
and thelinestyle
argument (whichscatter
doesn't actually use), and attempting to save the figure as a pdf withsavefig
triggers aValueError
.Code for reproduction
Actual outcome
A pdf file that cannot be opened is produced. The traceback is
Expected outcome
Because
show
works fine, and saving the figure as e.g. .png works fine, expected output is the saved figure as a pdf.That is:
Additional information
Error appears to be caused by the rendering being incorrectly routed to
RendererPdf.draw_path_collection
, which assumes there are some linewidths supplied, instead of the renderer that is normally used forscatter
.Expected output is achieved by changing line 2074 in
backend_pdf.py
tobut there is probably a more elegant/robust fix that ensures we route the pdf drawing correctly for a figure without lines, even if the
linestyle
kwarg is passed toscatter
.Operating system
MacOS 12.5.1
Matplotlib Version
3.8.4
Matplotlib Backend
MacOSX
Python version
3.11.5
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: