在熊猫的不同图表上绘制情节

时间:2018-12-28 14:21:06

标签: python pandas pandas-groupby

我的问题是,当我展示自己的地块时,大熊猫将它们相互吸引。我希望它们在不同的图表上。该怎么做?

代码:

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

train = pd.read_csv('./train.csv')
test = pd.read_csv('./test.csv')

survived = train[train['Survived'] == 1] # saving in variable all the people that survived
not_survived = train[train['Survived'] == 0] # saving in variable all the people that have not survived

tab = pd.crosstab(train['Pclass'], train['Sex'])
tab.div(tab.sum(1).astype(float), axis=0).plot(kind="bar", stacked=False)


train.groupby('Embarked').Survived.mean().plot(kind='line')

我得到的图表 enter image description here

1 个答案:

答案 0 :(得分:1)

这是如何将多个轴与熊猫图合并在一起

survived = train[train['Survived'] == 1] # saving in variable all the people that survived
not_survived = train[train['Survived'] == 0] # saving in variable all the people that have not survived

tab = pd.crosstab(train['Pclass'], train['Sex'])

fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = (10,5))

tab.div(tab.sum(1).astype(float), axis=0).plot(kind="bar", stacked=False, ax = ax[0])

train.groupby('Embarked').Survived.mean().plot(kind='line', ax = ax[1])

enter image description here