seaborn
seaborn copied to clipboard
Documentation for scatterplot: edgecolor(s) and linewidth(s)
Hello,
In the documentation of the scatterplot function, it is written that the remaining kwargs are passed down to the pyplot scatter function.
However, the pyplot scatter function has these 2 arguments: edgecolors
and linewidths
(plural). But in this example, they are not correctly applied:
x = [1, 2, 3, 4]
y = [4, 3, 2, 1]
sns.scatterplot(x=x, y=y, edgecolors="red", linewidths=2)
However, the singular terms work:
x = [1, 2, 3, 4]
y = [4, 3, 2, 1]
sns.scatterplot(x=x, y=y, edgecolor="red", linewidth=2)
I don't know if this is for compatibility issue with other plotting function, but this is a bit confusing.
Have a nice day!
The reason edgecolors
and linewidths
appear not to work is that seaborn sets defaults for edgecolor
and linewidth
, and those parameters take precedence over their plural counterparts in matplotlib.
I don't know why matplotlib has both the singular and plural versions; they appear to have identical functionality (i.e., you might think you could only pass a singleton value to the singular parameter names and an array of values to the plural parameter name, but that's not the case and they both accept singular or plural without apparent issue). Vexingly, the fact that the plural names are actually documented in the signature for plt.scatter
probably leads one to think they are more important, not less.
IMO matplotlib should probably raise when it gets values for both parameters.
If you use short form kwargs (sns.scatterplot(..., ec=..., lw=...)
you need not worry about this.
It would require some testing, but it would probably be fine to switch seaborn's internals to use the plural versions of the names when it sets the defaults; that seems simpler than doing the bookkeeping of tracking both versions of the parameters (and the short-form names), and the order of precedence in matplotlib should mean that the user's selections will be honored whether they use the singular or plural form.
For future reference, the relevant line would be here.
I kicked this upstream but will leave open as I think there's a reasonably small change that could be made in seaborn.
Hi @mwaskom, I just stumbled upon the same problem and it took me quite a while to understand what is going on. Is there any update on this yet? I think simply using short form kwargs as you suggested is fine for me in the meantime. However, being fairly new to matplotlib/seaborn, is there some comprehensive resource listing all the short form counterparts somewhere on the web? I couldn't seem to find one.
I'm not sure ... it would be in the matplotlib docs if there were.
Closing as matplotlib now raises when both singular and plural forms of these parameters are passed, so there's an explicit exception for the reprex here. It's not the most clear diagnosis of the issue, but it's much better than having the parameters silently ignored.