0
g = sns.lmplot(x='x', y='y', df, fit_reg=False, hue='z', lowess=True, scatter_kws={'alpha': 0.5}, legend=True)
plt.legend(bbox_to_anchor=(1.01, 0.5), ncol=2)

In the code above, if I set legend=True, I get both the default single column seaborn legend and the matplotlib legend. If I set `legend=False', then I get neither. How do I draw only the matplotlib 2 column legend?

1 Answer 1

3

Access the legend property via g.ax:

# example data
N = 100
data = {"x":np.random.random(N),
        "y":np.random.random(N),
        "z":np.random.choice([0,1], size=N)}
df = pd.DataFrame(data)

g = sns.lmplot(x='x', y='y', data=df, fit_reg=False, hue='z', 
               lowess=True, scatter_kws={'alpha': 0.5}, legend=False)
g.ax.legend(bbox_to_anchor=(1.01, 0.5), ncol=2)

scatter plot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.