seaborn icon indicating copy to clipboard operation
seaborn copied to clipboard

Documentation for scatterplot: edgecolor(s) and linewidth(s)

Open weber-s opened this issue 4 years ago • 4 comments

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)

not_working

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)

working

I don't know if this is for compatibility issue with other plotting function, but this is a bit confusing.

Have a nice day!

weber-s avatar Dec 15 '20 09:12 weber-s

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.

mwaskom avatar Dec 15 '20 12:12 mwaskom

I kicked this upstream but will leave open as I think there's a reasonably small change that could be made in seaborn.

mwaskom avatar Dec 15 '20 12:12 mwaskom

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.

wolfgang-koch avatar Apr 05 '21 13:04 wolfgang-koch

I'm not sure ... it would be in the matplotlib docs if there were.

mwaskom avatar Apr 05 '21 14:04 mwaskom

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.

mwaskom avatar Aug 27 '23 20:08 mwaskom