raju raju - 2 months ago 7
Python Question

How to see the plot made in python using pandas and matplotlib

I am following the tutorial http://ahmedbesbes.com/how-to-score-08134-in-titanic-kaggle-challenge.html and following is my code

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))


I dont actually see the plot. How do i see the plot?

enter image description here

Answer

Try using plt.show() at the end.

EDIT:

Also, you may need to add %matplotlib inline as explained here: How to make IPython notebook matplotlib plot inline

Comments