I created a lineplot graph to begin with using the following code:
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("")
I have realised that its actually a catplot chart that I need so I amended the code to the following:
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("")
However I am getting the following error message with the title: 'AttributeError: 'FacetGrid' object has no attribute 'set_title''.
Why is my title not working for the catplot chart?
When you call catplot, it returns a FacetGrid object, so to change the the title and remove legend, you have to use the legend=
option inside the function, and also use plot.fig.suptitle()
:
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"})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With