Skip to content
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

Feature request: add a legend_kws arg in sns.scatterplot in order to facilitate legend customization #3814

Open
JosephBARBIERDARNAL opened this issue Jan 17, 2025 · 2 comments

Comments

@JosephBARBIERDARNAL
Copy link

Hi!

It would be great if we could pass arguments directly to ax.legend() from sns.scatterplot (and potentially many other Seaborn functions) using a parameter like legend_kws (or something similar).

The idea would look like this:

sns.scatterplot(
    x=x,
    y=y,
    hue=hue,
    legend_kws={
        "reverse": True,
        "loc": "center left",
        "labelcolor": "red"
    }
)

I’m not sure if this has been considered already, but if adding this feature interests you, I’d be happy to work on it. I haven’t contributed to Seaborn before, but this seems like a relatively straightforward enhancement (or not?)—I just took a quick look at _ScatterPlotter.

@mwaskom
Copy link
Owner

mwaskom commented Jan 26, 2025

I've thought about adding this; it's not a bad idea.

But it's not something that could be added only to scatterplot. It would need to be added to any function in the sns namespace that produces a legend by default. I'm not sure how much work it will be to thread the kwargs dict down to the right place in all the relevant functions. Also you'd need to account for the fact that some functions do their own overriding of default legend kwargs, and that seaborn uses some hacks to achieve the "multi-variable legend" in the relational plotting functions. So it might be a lot of annoying work.

The sns.move_legend function should probably satisfy most or all usecases, although it's a little less obvious.

@JosephBARBIERDARNAL
Copy link
Author

OK, I see.

I hadn't thought of using sns.move_legend, but it does make sense to use it. It seems practical enough for what I had in mind. I'll let you close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants