Matplotlib chart is a no-show

When i run this code

import pandas as pd import numpy as np def add_prop(group): births = group.births.astype(float) group['prop'] = births/births.sum() return group pieces = [] columns = ['name', 'sex', 'births'] for year in range(1880, 2012): path = 'yob%d.txt' % year frame = pd.read_csv(path, names = columns) frame['year'] = year pieces.append(frame) names = pd.concat(pieces, ignore_index = True) total_births = names.pivot_table('births', rows = 'year', cols = 'sex', aggfunc = sum) total_births.plot(title = 'Total Births by sex and year') 

I have no plot. This is from Wes McKinney's book on using Python to analyze data. Can someone point me in the right direction?

+57
python matplotlib pandas
May 13 '13 at 12:44
source share
3 answers

Placed

 import matplotlib.pyplot as plt 

above and

 plt.show() 

in the end.

+162
May 13 '13 at 12:56
source share

On an IPython laptop, you can also use the %matplotlib inline at the top of the laptop to automatically display the generated graphs in the output cells.

+30
Dec 02 '13 at 18:06
source share

your code is correct. just put:

 import matplotlib as plt 

To mark up your plot:

 plt.show() 
+1
Nov 10 '17 at 9:27
source share



All Articles