我用的编译器的jupyter notebook
1 作图相关的
matplotlib
import matplotlib.pyplot as plt
#解决绘图中文乱码问题
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
#调整绘图尺寸
plt.rcParams['figure.figsize'] = (10.0, 8.0)
#组合图,2行3列,第0行1列
plt.subplot2grid((2,3),(0,1))
data_train.Pclass.value_counts().plot(kind='bar')
plt.ylabel("人数")
plt.title("乘客等级分布")
#画两个数据在一张图上
plt.figure()
fig.set(alpha=0.2)
Surived_m = data_train.Survived[data_train.Sex == 'male'].value_counts()
Surived_f = data_train.Survived[data_train.Sex == 'female'].value_counts()
df = pd.DataFrame({'男性':Surived_m,'女性':Surived_f})
df.plot(kind='bar',stacked=True)
plt.title('按性别看获救情况')
plt.xlabel('性别')
plt.ylabel('人数')
#共享坐标轴
fig=plt.figure()
fig.set(alpha=0.65) # 设置图像透明度,无所谓
plt.title(u"根据舱等级和性别的获救情况")
ax1=fig.add_subplot(141)
data_train.Survived[data_train.Sex == 'female'][data_train.Pclass != 3].value_counts().plot(kind='bar', label="female highclass", color='#FA2479')
ax1.set_xticklabels([u"获救", u"未获救"], rotation=0)
ax1.legend([u"女性/高级舱"], loc='best')
#这里的sharey=ax1的意思是与ax1共享坐标轴
ax2=fig.add_subplot(142, sharey=ax1)
data_train.Survived[data_train.Sex == 'female'][data_train.Pclass == 3].value_counts().plot(kind='bar', label='female, low class', color='pink')
ax2.set_xticklabels([u"未获救", u"获救"], rotation=0)
plt.legend([u"女性/低级舱"], loc='best')