0

I'm using seaborn to create a density plot with the following command lines

# set seaborn whitegrid theme
sns.set(style="whitegrid")

sns.kdeplot(data = dfSPSSstudent, x='entIntention_mean', hue='Q2_1a')

#define figure size
sns.set(rc={"figure.figsize":(18, 14)}) #width=8, height=4

# Put the legend out of the figure
#ax.legend(bbox_to_anchor=(1.05, 1), loc=2)
plt.legend(labels = dfSPSSstudent['Q2_1a'], loc = 'upper left', bbox_to_anchor = (1,1))
plt.show()

I have a very strange legend compared to the results I have when counting the different categories of Q2_1a.

an employee in a large business (250 or more employees)      437
Other / do not know yet                                      373
an employee in a medium-sized business (50-249 employees)    370
an employee in a small business (1-49 employees)             261
a founder (entrepreneur) working in my own business          107
an employee in public service                                101
an employee in academia (academic career path)                78
an employee in a non-profit organization                      51
a successor in my parents’ / family’s business                16
a successor in another business                               16

Do you know how to solve the issue?

enter image description here

This is working fine without legend outside the plot enter image description here

fredooms
  • 123
  • 8
  • 1
    You need `ax = sns.kdeplot(...)`, `ax.legend_.set_bbox_to_anchor((1.02, 1.02))`and `ax.legend_._set_loc(2) ` – JohanC Aug 29 '21 at 14:56

0 Answers0