Python 在单独的子地块中显示显示-Seaborn

Python 在单独的子地块中显示显示-Seaborn,python,pandas,seaborn,Python,Pandas,Seaborn,我的目标是将Seaborn显示器插入单独的子地块。使用下面的命令,我想将Label1传递到ax1和Label2传递到df2。但是,我得到一个警告:UserWarning:displaot是一个图形级函数,不接受ax=parameter。您可能希望尝试histplot。警告。警告(msg,UserWarning) 有办法解决这个问题吗?我以前在hue参数方面遇到过histplot问题。如果必要的话,我不愿意使用它 import pandas as pd import matplotlib.pypl

我的目标是将Seaborn显示器插入单独的子地块。使用下面的命令,我想将
Label1
传递到
ax1
Label2
传递到
df2
。但是,我得到一个警告:
UserWarning:displaot是一个图形级函数,不接受ax=parameter。您可能希望尝试histplot。警告。警告(msg,UserWarning)

有办法解决这个问题吗?我以前在
hue
参数方面遇到过
histplot
问题。如果必要的话,我不愿意使用它

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

fig, (ax1, ax2) = plt.subplots(1,2, figsize = (12,6))

df = pd.DataFrame({      
    'Num' : [1,2,1,2,3,2,1,3,2,2,1,2,3,3,1,3],
    'Label1' : ['A','B','C','B','B','C','C','B','B','A','C','A','B','A','C','A'],  
    'Label2' : ['D','E','D','F','E','D','F','E','F','D','E','F','E','D','D','F'],   
    'Item' : ['Up','Left','Up','Left','Down','Right','Up','Down','Right','Down','Right','Up','Up','Right','Down','Left'],        
   })

ax1 = sns.displot(data = df, 
               x = 'Label1', 
               hue = 'Num',
               row = 'Item', 
               row_order = ['Up','Down','Left','Right'],
               shrink = 0.9, 
               discrete = True,
               aspect = 4, 
               height = 2,
               ax = ax1
               )

ax2 = sns.displot(data = df, 
               x = 'Label2', 
               hue = 'Num',
               row = 'Item', 
               row_order = ['Up','Down','Left','Right'],
               shrink = 0.9, 
               discrete = True,
               aspect = 4, 
               height = 2,
               ax = ax2
               )

如果要避免使用
histplot()
,我认为使用
displat()
最接近的方法是
melt()
数据,并使用
col
Label1
Label2
分为两列:

sns.dislot(
data=df.melt(['Num','Item'],var\u name='Group',value\u name='Label'),
y='标签',
色调='Num',
行='Item',
col='组',
行顺序=[“上”、“下”、“左”、“右”],
收缩=0.9,
离散=真,
相位=4,
高度=2,
)