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

Getting error: No handles with labels found to put in legend. when moving legend outside of the box when plotting with kdeplot with searborn #2486

Closed
balandongiv opened this issue Feb 23, 2021 · 2 comments

Comments

@balandongiv
Copy link

I am plotting a kde plot using the seaborn kdeplot.

time_window_order=['272','268','264','260','256','252','248','244','240']
order_dict = {k:i for i,k in enumerate(time_window_order)}
df =DataFrame ({'time_window':['268','268','268','264','252','252','252','240',
                               '256','256','256','256','252','252','252','240'],
                'seq_no':['a','a','a','a','a','a','a','a',
                          'b','b','b','b','b','b','b','b']})
df['centre_point'] = df['time_window'].map(order_dict)

g =sns.kdeplot(data=df, x="centre_point",hue='seq_no', bw_adjust=0.8);plt.xlim(0,len(time_window_order)-1);plt.grid()
g.legend(loc='center left', bbox_to_anchor=(1, 0.5)) # move legend outside the box
plt.xticks(ticks = range(0,len(time_window_order)) ,labels = time_window_order, rotation = 'vertical')
plt.show()

I tried reposition the legend outside the box using the line g.legend(loc='center left', bbox_to_anchor=(1, 0.5)) [link].

Instead, the compiler return an error

No handles with labels found to put in legend.

Also, instead of complete legend, the legend appear to become like a small rectangle as shown by the red arrow, in the figure attached
kde_PLot
.

May I know how to fix this or whether this is bug?

@mwaskom
Copy link
Owner

mwaskom commented Feb 23, 2021

It is the same question as #2280

More information there, but I would suggest using displot if you want the legend outside of the plot and it otherwise works for you.

@balandongiv
Copy link
Author

It is the same question as #2280

More information there, but I would suggest using displot if you want the legend outside of the plot and it otherwise works for you.

Thanks for suggesting the displot

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