[英]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. 这是来自Wes McKinney关于使用Python进行数据分析的书。 Can anyone point me in the right direction? 谁能指出我正确的方向?
Put 放
import matplotlib.pyplot as plt
at the top, and 在顶部,和
plt.show()
at the end. 在末尾。
在IPython笔记本中,您还可以在笔记本顶部使用%matplotlib inline
,以自动在输出单元格中显示创建的图。
your code is correct. 你的代码是正确的。 just put: 刚刚放:
import matplotlib as plt
for diplaying you plot: 用于绘制你的情节:
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.