-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jointplot doesn't return handles and labels #2677
Comments
Could you please provide a reproducible example? Thanks. |
|
I assume you want this data because you want to move the legend. (It can be helpful when opening an issue to provide context about what you're trying to do beyond the specific operation that isn't working). If that's the case I'd refer you to this issue. Otherwise, this is not a bug from my perspective (nor does it have anything to do with If you're trying to do some customization other than moving the legend it may be better to ask on stackoverflow. |
I actually wanted to change the labels in the legend for the kde-plot like this:
In the above, the first two labels in I only managed to do this by not using
which does allow me to access the handles and labels for the kde-plot with So, an example of a working code in my instance:
But this is not satisfactory, because it leaves the points from the sns.jointplot in the background. |
I don't think this example is "working", at least not in the way you want, because those are not handles for the KDE plot; they are handles for scatterplot points. See what happens when you try to recreate the legend with them: g = sns.jointplot(data=df, x='x', y='y', hue='group')
g.plot_joint(sns.kdeplot)
g.ax_joint.legend(*g.ax_joint.get_legend_handles_labels())
The officially-supported way to change the labels that seaborn adds is to send different data into its functions. Or you can manipulate the matplotlib objects after plotting. Unfortunately, the matplotlib legend object is less flexible than the Axes or the Artists that comprise the plot, but you can modify the legend text objects: texts = g.ax_joint.legend_.texts
for t, label in zip(texts, "ABC"):
t.set_text(label) Closing as there's no bug here on the seaborn side. |
I noticed that when using
g = sns.jointplot(data=data, x="X", y="Y", hue="Group", kind="kde")
we don't get handles or labels when using
print(g.ax_joint.get_legend_handles_labels())
However, removing the "kind" keyword does print handles and labels - it doesn't matter what you insert as the input to "kind", but it always seems to override the handles and labels from "hue". Is there an easy fix for this?
The text was updated successfully, but these errors were encountered: