import seaborn as sns import matplotlib.pyplot as plt data = sns.load_dataset("titanic") print(data.head()) g = sns.catplot(x="class", y="survived", hue="sex", data=data, height=6, kind="bar", palette="muted") g.set_ylabels("survival probability") plt.show()
运行结果:
survived pclass sex age ... deck embark_town alive alone 0 0 3 male 22.0 ... NaN Southampton no False 1 1 1 female 38.0 ... C Cherbourg yes False 2 1 3 female 26.0 ... NaN Southampton yes True 3 1 1 female 35.0 ... C Southampton yes False 4 0 3
male 35.0 ... NaN Southampton no True
显示效果: