Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib plot 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 get no plot. This is from Wes McKinney's book on using Python for data analysis. Can anyone point me in the right direction?

like image 612
ncmathsadist Avatar asked May 13 '13 12:05

ncmathsadist


People also ask

Why is matplotlib not showing plot?

The issue actually stems from the matplotlib backend not being properly set, or from a missing dependency when compiling and installing matplotlib.

Why is my plot blank in Python?

The reason your plot is blank is that matplotlib didn't auto-adjust the axis according to the range of your patches.

What is matplotlib use (' AGG ')?

The last, Agg, is a non-interactive backend that can only write to files. It is used on Linux, if Matplotlib cannot connect to either an X display or a Wayland display.


1 Answers

Put

import matplotlib.pyplot as plt 

at the top, and

plt.show() 

at the end.

like image 142
unutbu Avatar answered Oct 13 '22 21:10

unutbu