0

In countplot legend for hue are placed at improper positition:

sns.countplot(x='cat114', hue='loss', data=data_tr)

Countplot

How do I change legend position? I tried plt.legend(loc='upper right') but it is not helping me.

  • Did you put `plt.legend(loc='upper right')` before or after the `countplot`? – tdy Mar 26 '21 at 04:50
  • I put it after. I got my answer btw, g=sns.countplot(x=feature, hue='loss', data=data_tr, order=cat_order(feature)) g.figure.get_axes()[0].legend(loc='upper right') – Sandeep Maurya Mar 26 '21 at 05:05
  • Sounds good. Feel free to post that as an official answer and accept it. – tdy Mar 26 '21 at 05:07

1 Answers1

0
g=sns.countplot(x=feature, hue='loss', data=data_tr) 
g.figure.get_axes()[0].legend(title='loss',loc='upper right')