Comments (2)
linestyle
is a bit of a strange argument to be passing to scatter
. It is not entirely wrong, just may not do what you expect.
If you are expecting a line between your points, then plot
is the method to use.
What it is actually controlling, though, is the lines of the markers themselves. This is actually done through **kwargs
eventually being passed through the Collection
.
Now, given that that is what you want, ""
is itself a bit of an edge case, as that is indicated not to draw the line, rather than really adjusting how it is drawn.
In Line2D, the various forms of "linestyle for not having the line" are normalized to "None"
:
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 plt.scatter(..., linestyle="None")
it does not error, but a line is still drawn...
A quick way to get the desired effect would be to use linewidth=0
instead of adjusting line style. This is actually what is done internally for Patch
objects when linestyle is set to "None" (or "", or " ", etc).
Anyway, the Collection set_linestyle
mostly wraps mpl.lines._get_dashpattern
, just handling the broadcasting since collections are plural:
matplotlib/lib/matplotlib/collections.py
Lines 591 to 631 in 8fb842c
The _get_dashpattern
function actually returns the same thing for "None"
or "solid":
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 ""
, the set_linestyle
code for Collection
will actually result in an empty list (the try
section errors, which brings it to the except
which loops over the empty string, resulting an an empty list... other aliases will result in an error message at call time):
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 zip
including the empty list? but does not error.) The pdf backend errors
Docs wise, the "None" case, which appears in the Line2D.set_linestyle
docstring table is actually left out of the Collection.set_linestyle
docstring, though ""
does still appear in the parameters
section listed, and it crosslinks to the Line2D
version as the more complete reference.
Proposed solution:
- Handle aliasing/special casing of "None" in
Collections.set_linestyle
- Handle interpretting the special case in
Collections._bcast_lwls
to setlw
to 0 forls="None"
.
TL;DR:
- Right now you can use
linewidth=0
to get the desired effect - In all, internally it is a bit frustrating that everything implements turning off a line via line styling ever so slightly differently, but I think we should likely support it here
from matplotlib.
Thank you for the thorough and quick response! I'm aware that it really doesn't make sense to pass a linestyle
to scatter
, but I often use plot(*args, linestyle='')
if I'm scattering many points with the same color, as scatter
can be quite a bit slower if there are many points (at least I remember that being the case some years ago, please correct me if I'm wrong). The reason I came across this was that I modified some code to set different colors on the points, and forgot to remove the linestyle
kwarg (which I think may be not-so-uncommon to do).
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 show
work as expected.
I think it would be a perfectly reasonable fix to just throw an error if linestyle
is passed to scatter
, but given that this can be handled elegantly in Collections.set_linestyle
or Collections._bcast_lwls
that would of course be preferable.
from matplotlib.
Related Issues (20)
- [Bug]: HOT 3
- [Bug]: `LinearSegmentedColormap.from_list` does not have all type hints for argument `colors`
- [Bug]: Can't save with custom toolbar
- [TST] Upcoming dependency test failures HOT 1
- [Bug]: `ax.transData` does not honor data limits HOT 8
- [ENH]: Make FontManager._find_fonts_by_props public.
- [Doc]: Subheading links do not scroll to the appropriate page anchor HOT 8
- [Bug]: `FigureCanvasPgf` does not use `xelatex` HOT 2
- [ENH]: Add a QtPgfPng backend? HOT 8
- Toolbar is not scaled properly on either of wx[agg,cairo] when displays with multiple resolutions are present. HOT 1
- [Bug]: Setting norm by string doesn't work for hexbin HOT 2
- [TST] Upcoming dependency test failures HOT 1
- [Bug]: PGF backend uses incorrect xtick.labelsize and ytick.labelsize when they are small HOT 3
- [Bug]: matplotlib suddenly starts to trouble with datetieme objects HOT 4
- [Bug]: mpl.colormaps[ "Grays" ].name is "Greys", not "Grays" HOT 7
- [Bug]: The zlabel on 3D axes will be cut when using '%matplotlib inline' in Jupyter
- [ENH]: Allow a custom documentclass when using the pgf backend.
- [Bug]: can not set ylabel fontsize in host_subplot HOT 1
- [ENH]: Format PercentFormatter based on usetex value HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matplotlib.