I created a density plot using Seaborn
like this:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame({'1': np.random.normal(1, 1, 20),
'2': np.random.normal(3, 1, 20)})
df = df.melt()
g = sns.displot(df, x='value', hue='variable', kind='kde')
Now, I would like to relocate the legend to the upper left. Normally I would do something like this:
plt.legend(loc='lower left', bbox_to_anchor=(0, 1))
However, it cannot find the axis labels and handles. I cannot get them manually either:
handles, labels = g.ax.get_legend_handles_labels()
Is there anyway I can get the handles and labels from the Seaborn FacetGrid to customize the legend?