我打算将Seaborn的显示插入到不同的子图中。使用下面的代码,我想将
Label1
传递给ax1
,将Label2
传递给df2
。然而,我收到了一个警告:UserWarning: displot是一个基于图形层的函数,不接受ax参数。你可能需要尝试histplot。warnings.warn(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
)