Python Seaborn标题错误-AttributeError:&x27;FaceGrid';对象没有属性';设置标题
首先,我使用以下代码创建了一个线形图:Python Seaborn标题错误-AttributeError:&x27;FaceGrid';对象没有属性';设置标题,python,seaborn,Python,Seaborn,首先,我使用以下代码创建了一个线形图: plot = sns.lineplot(data=tips, x="sex", y="tip", ci=50, hue="day", palette="Accent") plot.set_title("Value of Tips Given
plot = sns.lineplot(data=tips,
x="sex",
y="tip",
ci=50,
hue="day",
palette="Accent")
plot.set_title("Value of Tips Given to Waiters, by Days of the Week and Sex", fontsize=24, pad=30, fontdict={"weight": "bold"})
plot.legend("")
我意识到我需要的实际上是一个catplot图表,因此我将代码修改为以下内容:
plot = sns.catplot (data=tips,
x="day",
y="tip",
kind='bar',
ci=50,
hue="sex",
palette="Accent")
plot.set_title("Value of Tips Given to Waiters, by Days of the Week and Sex", fontsize=24, pad=30, fontdict={"weight": "bold"})
plot.legend("")
但是,我收到以下标题为的错误消息:“AttributeError:“FaceGrid”对象没有属性“set_title”
为什么我的标题不适用于catplot图表?调用catplot时,它会返回一个FacetGrid对象,因此要更改标题并删除图例,必须在函数内使用
legend=
选项,并使用plot.fig.suptitle()
:
这是否回答了您的问题?非常感谢,您是如何访问我正在使用的数据集的;)?!这是seaborn软件包的一部分<代码>提示=sns.load\u数据集(“提示”)
import seaborn as sns
tips = sns.load_dataset("tips")
plot = sns.catplot (data=tips,
x="day",
y="tip",
kind='bar',
ci=50,
hue="sex",
palette="Accent", legend=False)
plot.fig.suptitle("Value of Tips Given to Waiters, by Days of the Week and Sex",
fontsize=24, fontdict={"weight": "bold"})