Matplotlib: plot is a no-show,怎么办?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (22)

当我运行这段代码时

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

报错:plot is a no-show

提问于
用户回答回答于

import matplotlib.pyplot as plt

放在顶端,

plt.show()

用户回答回答于

在IPython笔记本中,您也可以使用%matplotlib inline在笔记本的顶部,自动显示在输出单元格中创建的图形。

扫码关注云+社区