在seaborn 0.11.2中将色调应用于PairGrid的下部或上部
提供了此问题的解决方案 这里。然而,对于最新版本的seaborn(0.11.2),它不起作用,而是产生单色的散点图。
这是之前提出的解决方案:
import matplotlib.pyplot as plt
import seaborn as sns
df = sns.load_dataset("iris", cache=True)
g = sns.PairGrid(df)
g.map_upper(sns.scatterplot)
g.map_diag(sns.kdeplot)
# Now set parameters needed for `hue`
g.hue_vals = df["species"]
g.hue_names = df["species"].unique()
g.palette = sns.color_palette("husl", len(g.hue_names))
# Then map lower
g.map_lower(sns.scatterplot)
plt.show()
产生:
任何人都可以提出一个适用于 Seaborn 0.11.2 的解决方案吗?
A solution to this problem was provided here. However, for a more recent version of seaborn (0.11.2), it doesn't work, instead yielding a scatter plot in a single color.
Here is the previously proposed solution:
import matplotlib.pyplot as plt
import seaborn as sns
df = sns.load_dataset("iris", cache=True)
g = sns.PairGrid(df)
g.map_upper(sns.scatterplot)
g.map_diag(sns.kdeplot)
# Now set parameters needed for `hue`
g.hue_vals = df["species"]
g.hue_names = df["species"].unique()
g.palette = sns.color_palette("husl", len(g.hue_names))
# Then map lower
g.map_lower(sns.scatterplot)
plt.show()
which yields:
Can anyone propose a solution to this problem that will work for Seaborn 0.11.2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我会这样做
您也可以采用其他方式,仅在
map_upper
调用中分配hue
。但要正确地理解这个传说是很困难的。I guess I would do this
You could do it the other way, only assigning
hue
in themap_upper
call. But it would be tricker to get the legend right.