海上出生的情节,图例与人物重叠

2024-09-25 00:33:38 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Seaborn,无论我使用的是什么数据帧,或者我使用的是PairPlot还是jointgrids,我的图例都会与数据重叠。我知道我可以通过删除Seaborn的传奇并制作自定义传奇来解决这个问题,但是,这不是“最干净”的路线。如何让Seaborn创建不重叠的图例

下面是一些代码:

g = sns.pairplot(df, kind="reg", plot_kws={"marker": "+"}, hue="experiment", palette="Set2", x_vars=["alpha [%]", "shelter [%]", "beta [%]"], y_vars=["final [%]"])

plt.show()

(顺便说一句,我使用的是Mac OS、Pycharm、Python 3.6seaborn 0.10.0和matplotlib 3.3.3)


Tags: 数据代码dfplotvarsseabornreg路线
1条回答
网友
1楼 · 发布于 2024-09-25 00:33:38

看来你不能用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 use PairGrid directly if you need more flexibility.

使用this ^{} example from the docs,可以将loc参数传递给add_legend()方法

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()

可以传递给loc参数的参数列在Matplotlib docs

相关问题 更多 >