如何使用pandas和matplotlib查看python中的绘图

时间:2016-09-07 17:04:25

标签: python matplotlib kaggle

我正在关注教程http://ahmedbesbes.com/how-to-score-08134-in-titanic-kaggle-challenge.html,以下是我的代码

from IPython.core.display import HTML
HTML("""
<style>
.output_png {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}
</style>
""")

# remove warnings
import warnings
warnings.filterwarnings('ignore')
# ---

import pandas as pd
pd.options.display.max_columns = 100
import matplotlib

matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import numpy as np

pd.options.display.max_rows = 100


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

data.head()

data['Age'].fillna(data['Age'].median(), inplace=True)
survived_sex = data[data['Survived']==1]['Sex'].value_counts()
dead_sex = data[data['Survived']==0]['Sex'].value_counts()
df = pd.DataFrame([survived_sex,dead_sex])
df.index = ['Survived','Dead']
df.plot(kind='bar',stacked=True, figsize=(15,8))

我实际上没看到情节。我怎么看情节?

enter image description here

1 个答案:

答案 0 :(得分:1)

最后尝试使用plt.show()

编辑:

此外,您可能需要按照此处的说明添加%matplotlib inlineHow to make IPython notebook matplotlib plot inline