I am trying to create a Seaborn Histogram Plot showing the frequency of Time In Shelter per Outcome Type. The legend is meant to show the Outcome Type per colour on the Histogram but it's not being displayed. I am getting an error message saying "No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument". My code is as follows:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Plotting histogram for time in shelter per outcome distribution:
plt.figure(figsize=(10, 5))
sns.histplot(data=shelter_df, x='Time In Shelter', hue='Outcome Type', multiple='stack', bins=15)
plt.xlabel('Time In Shelter in Days', fontsize = 14)
plt.ylabel('Frequency', fontsize = 14)
plt.title('Time in Shelter per Outcome Distribution', fontsize = 14)
# Adjusting Seaborn's legend parameters:
plt.legend(title = 'Outcome Type', title_fontsize = 14, fontsize = 10, loc='upper right')
plt.xticks(size = 10)
plt.yticks(size = 10)
plt.show()
Any ideas please? Thanks
I tried putting label = 'Outcome Type' in the sns.histplot() parenthesis but I get the image below with 'Outcome type' listed for every single colour instead of the actual outcome types: enter image description here