You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中使用Seaborn的factorplot报错AttributeError求助

解决Seaborn中factorplot不存在的报错问题

问题原因

Seaborn在v0.11.0版本后移除了factorplot函数,它的功能被统一整合到更通用的catplot()函数中,这就是你遇到AttributeError的核心原因。

解决方法

直接将代码中的sns.factorplot()替换为sns.catplot()即可,两者参数完全兼容:

修改后的代码:

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

# 替换factorplot为catplot
sns.catplot(data=auto, x="fuel-type", y="horsepower", hue="num-of-doors")
plt.show()

额外说明

  • catplot默认生成的图表类型和原factorplot一致(箱线图),如果需要其他类型的分类图表,只需指定kind参数:
    • 柱状图:kind="bar"
    • 点图:kind="point"
    • 小提琴图:kind="violin"
  • 不推荐降级Seaborn到0.10.x版本来使用旧的factorplot,后续版本会持续更新功能并修复bug。

内容的提问来源于stack exchange,提问作者Hussain Ali Gondal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 00:25:59