[英]How to plot Pandas multilabel data scatterplots in Seaborn using facetgrid?
I have a dataset which have multiple labels. 我有一个具有多个标签的数据集。 I want to create a Facetgrid of scatterplots using Pandas and Seaborn.
我想使用Pandas和Seaborn创建一个散点图的Facetgrid。 In addition this dataset has different origin which I also want to compare.
另外,该数据集具有不同的来源,我也想比较一下。 (For example, this could be the prediction of different ML algorithms and the true labeling in two plots side by side).
(例如,这可能是对不同ML算法的预测以及在两个图中并排显示的真实标签)。 The plot I want is something like this with room for more methods and labelings:
我想要的图是这样的,还有更多方法和标签的空间:
Here the right column is the first labeling and the left is the second. 在这里,右列是第一个标签,左列是第二个标签。
Currently my Pandas dataframe looks like this: l1, l2, method, x, y. 目前,我的Pandas数据框如下所示:l1,l2,method,x,y。 Where l1 and l2 are the different labelings.
其中l1和l2是不同的标签。 I can plot one column using the following code:
我可以使用以下代码绘制一列:
g = sns.FacetGrid(df, row='method', hue='l1')
g.map(plt.scatter, 'x', 'y')
sns.plt.show()
But how do I get the second column? 但是,如何获得第二列? The intuitive thing would be to have the hue parameter be a list but that doesn't work.
直观的事情是将hue参数作为一个列表,但这不起作用。
I think you need to modify your dataframe: 我认为您需要修改数据框:
l1_df = df[['l1','method','x','y']]
l1_df['label_type'] = 'l1'
l1_df.rename(columns={'l1':'label'}, inplace=True)
l2_df = df[['l2','method','x','y']]
l2_df['label_type'] = 'l2'
l2_df.rename(columns={'l2':'label'}, inplace=True)
df = pd.concat([l1_df,l2_df])
Then use the truly intuitive option, col
, from the docs : 然后从docs使用真正直观的选项
col
:
g = sns.FacetGrid(df, row='method', col='label_type', hue='label')
g.map(plt.scatter, 'x', 'y')
sns.plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.