Reputation: 85
Using Seaborn, my legend keeps overlapping the data, no matter what dataframe I use, or whether I use pairplots or jointgrids. I know I can work around this by removing Seaborn's legend and making a custom legend, however, that's not the "cleanest" route. How can I get Seaborn to create non-overlapping legends ?
Here some code:
g = sns.pairplot(df, kind="reg", plot_kws={"marker": "+"}, hue="experiment", palette="Set2", x_vars=["alpha [%]", "shelter [%]", "beta [%]"], y_vars=["final [%]"])
plt.show()
(btw I'm on Mac OS, Pycharm, Python 3.6seaborn 0.10.0 and matplotlib 3.3.3)
Upvotes: 1
Views: 832
Reputation: 69
It seems you can not do it with pairplot
. In the docs they say:
This is a high-level interface for
PairGrid
that is intended to make it easy to draw a few common styles. You should usePairGrid
directly if you need more flexibility.
Taking this PairGrid
example from the docs, you can pass the loc
parameter to the add_legend()
method.
g = sns.PairGrid(penguins, hue="species")
g.map_diag(sns.histplot)
g.map_offdiag(sns.scatterplot)
g.add_legend(loc=(0.9,0.2)) # or g.add_legend(loc="upper right");
plt.show()
The arguments you can pass to the loc
parameter are listed in the Matplotlib docs.
Upvotes: 1