2024-04-28 22:56:22 发布
网友
Seaborn的catplot似乎无法与plt.子批次(). 我不知道这是什么问题,但我似乎不能把它们放在一起。在
#Graph 1 plt.subplot(121) sns.catplot(x="HouseStyle",y="SalePrice",data=df,kind="swarm") #Graph 2 plt.subplot(122) sns.catplot(x="LandContour",y="SalePrice",data=df,kind="swarm")
输出:
您需要在绘图时将创建的轴传递给seaborn的catplot。下面是一个示例答案。有几件事
catplot
add_subplot
plt.close()
close()
完整的可重复答案
import seaborn as sns import matplotlib.pyplot as plt exercise = sns.load_dataset("exercise") fig = plt.figure() ax1 = fig.add_subplot(121) g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise, ax=ax1) # pass ax1 ax2 = fig.add_subplot(122) g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise, ax=ax2) # pass ax2 plt.close(2) plt.close(3) plt.tight_layout()
您需要在绘图时将创建的轴传递给seaborn的
catplot
。下面是一个示例答案。有几件事add_subplot
来创建类似您的子批次catplot
仍将返回一个axis对象,该对象可以使用plt.close()
关闭,其中括号内的数字对应于数字计数。有关close()
的详细信息,请参见this answer完整的可重复答案
相关问题 更多 >
编程相关推荐