raju raju - 1 year ago 161
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
.output_png {
display: table-cell;
text-align: center;
vertical-align: middle;

# remove warnings
import warnings
# ---

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

import matplotlib.pyplot as plt
import numpy as np

pd.options.display.max_rows = 100

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


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 Source

Try using plt.show() at the end.


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download