[英]How to change the z-order of the plot elements in a seaborn pairplot
Here is a snippet, to reproduce my example image:这是一个片段,用于重现我的示例图像:
import pandas as pd
import numpy as np
import seaborn as sns
np.random.seed(42)
df = pd.DataFrame(np.random.rand(10,2), columns=['x', 'y'])
df['label'] = ['cat', 'mouse', 'dog', 'mouse', 'cat', 'cat', 'mouse', 'mouse','dog', 'cat']
sns.pairplot(df, hue='label');
It produces the following seaborn pair plot, with some dummy data:它产生以下 seaborn 对 plot,以及一些虚拟数据:
In the upper right plot, one marker of the 'dog' category is below an overlaying marker of the 'mouse' category.在右上角 plot 中,“狗”类别的一个标记位于“鼠标”类别的覆盖标记下方。
Can I somehow change the z-order of the scatter plot markers, so that all markers of the 'dog' category are best visible on top?我可以以某种方式更改散点图 plot 标记的 z 顺序,以便“狗”类别的所有标记在顶部最清晰可见吗?
edit: I already tried hue_order=['mouse', 'cat', 'dog']
and hue_order=['dog', 'mouse', 'cat']
, but they only influence the order in the legend and the color.编辑:我已经尝试过
hue_order=['mouse', 'cat', 'dog']
和hue_order=['dog', 'mouse', 'cat']
,但它们只影响图例中的顺序和颜色。 Not the z-order of the markers in the scatter plot.不是散点图 plot 中标记的 z 顺序。
pd.concat([df[df['label'],= 'dog'], df[df['label'] == 'dog']])
.pd.concat([df[df['label'],= 'dog'], df[df['label'] == 'dog']])
。import pandas as pd
import numpy as np
import seaborn as sns
np.random.seed(42)
df = pd.DataFrame(np.random.rand(10, 2), columns=['x', 'y'])
df['label'] = ['cat', 'mouse', 'dog', 'mouse', 'cat', 'cat', 'mouse', 'mouse', 'dog', 'cat']
sns.pairplot(pd.concat([df[df['label'] != 'dog'], df[df['label'] == 'dog']]), hue='label')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.