Matplotlib plot is a no-show

PythonMatplotlibPandas

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

Put

import matplotlib.pyplot as plt

at the top, and

plt.show()

at the end.

Solution 2 - Python

In the IPython notebook you could also use %matplotlib inline at the top of the notebook to automatically display the created plots in the output cells.

Solution 3 - Python

your code is correct. just put:

import matplotlib as plt

for diplaying you plot:

plt.show()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionncmathsadistView Question on Stackoverflow
Solution 1 - PythonunutbuView Answer on Stackoverflow
Solution 2 - PythonjmzView Answer on Stackoverflow
Solution 3 - PythonAkash NayakView Answer on Stackoverflow