Pandas 为什么';t set_标题产生了一个标题(Seaborn和FactoryPlot)?

Pandas 为什么';t set_标题产生了一个标题(Seaborn和FactoryPlot)?,pandas,matplotlib,seaborn,Pandas,Matplotlib,Seaborn,这是我正在使用的代码。这是一个自包含的代码,可以复制和粘贴 import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt ### Load the Titanic dataset titanic = sns.load_dataset("titanic") ### Divide the data by sex; male and female male = tita

这是我正在使用的代码。这是一个自包含的代码,可以复制和粘贴

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



### Load the Titanic dataset
titanic = sns.load_dataset("titanic")

### Divide the data by sex; male and female

male = titanic[titanic.sex == 'male']
female = titanic[titanic.sex == 'female']




### Now use groupby to group by fare//5 and then create a column with the  survival rate for each group

male_chart= male.groupby([male.fare // 5]).survived.mean().reset_index()
female_chart= female.groupby([female.fare // 5]).survived.mean().reset_index()



#Plot male_chart
sns.set(style="whitegrid")
g = sns.factorplot(x='fare', y= 'survived',  data=male_chart,
               size=6, aspect =3 ,kind="bar", palette="muted")

g.despine(left=True)
g.set_ylabels("Survival Probability")
g.set_xlabels('Fare *5')
g.set_titles('Males')   # set_title doesn't produce "Males" on the chart itself



#sns.plt.title('Males')   #This code seems to work but not sure why it does. 


#plot: female_chart

h= sns.factorplot(x='fare', y= 'survived',  data=female_chart,
               size=6, aspect =3 ,kind="bar", palette="muted")
h.despine(left=True)
h.set_ylabels("survival probability")
h.set_xlabels('fare *5')
h.set_titles('Females')  #Once again doesn't work.
#sns.plt.title('Females')  #but this works
plt.show()
我在运行“set_titles”行时没有收到任何错误,但它不会在图形本身上生成标题。
我如何错误地使用set_title?谢谢你的帮助

set\u titles
用于具有
col
/
刻面的情况,此处不使用该刻面。你需要
g.ax.set_title()
。当我想传达有用的信息,但没有时间写出完整的答案时,我会这样做。