第1关 存活率与性别和船舱等级之间的关系
import pandas as pd
import numpy as np
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
sns.set()
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
def student():
# ********* Begin *********#
a = pd.read_csv('Task1/train.csv')
fig,axes = plt.subplots(1,2)
sns.violinplot(x='Pclass',y='Age',data=a,split=True,ax=axes[0],hue='Survived')
sns.violinplot(x='Sex',y='Age',split=True,data=a,hue='Survived',ax=axes[1])
plt.savefig('Task1/img/T1.png')
plt.show()
# ********* End *********#
第2关 各个口岸的生还率
import pandas as pd
import numpy as np
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
sns.set()
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
def student():
# ********* Begin *********#
a = pd.read_csv('Task2/train.csv')
sns.factorplot(data=a,x='Embarked',y='Survived')
plt.savefig('Task2/img/T1.png')
plt.show()
# ********* End *********#
第3关 统计各登船口岸的登船人数以及生还率
import pandas as pd
import numpy as np
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
sns.set()
import matplotlib.pyplot as plt
def student():
# ********* Begin *********#
a = pd.read_csv('Task3/train.csv')
fig,ax = plt.subplots(2,2,figsize=(10,10))
sns.countplot("Embarked",data=a,ax=ax[0,0])
ax[0,0].set_title("No.Of Passengers Boarded")
sns.countplot("Embarked",hue="Sex",data=a,ax=ax[0,1])
ax[0,1].set_title("Male-Female Split for Embarked")
sns.countplot("Embarked",hue="Survived",data=a,ax=ax[1,0])
ax[1,0].set_title("Embarked vs Survived")
sns.countplot("Embarked",hue='Pclass',data=a,ax=ax[1,1])
ax[1,1].set_title("Embarked vs Pclass")
plt.savefig("Task3/img/T1.jpg")
plt.show()
# ********* End *********#
第4关 船客兄弟姐妹妻子丈夫的数量与生存率之间的关系
import pandas as pd
import numpy as np
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
sns.set()
import matplotlib.pyplot as plt
def student():
# ********* Begin *********#
data = pd.read_csv("Task4/train.csv")
f,ax = plt.subplots(1,2,figsize=(10,10))
sns.barplot(x="SibSp",y="Survived",data=data,ax=ax[0])
ax[0].set_title("SibSp vs Survived")
sns.catplot(x="SibSp",y="Survived",data=data,ax=ax[1],kind="point")
ax[1].set_title("SibSp vs Survived")
plt.close(2)
plt.savefig("Task4/img/T1.png")
# ********* End *********#