Python Matplotlib 绘图未出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16522380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matplotlib plot is a no-show
提问by ncmathsadist
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?
我没有情节。这是来自 Wes McKinney 的关于使用 Python 进行数据分析的书。任何人都可以指出我正确的方向吗?
采纳答案by unutbu
Put
放
import matplotlib.pyplot as plt
at the top, and
在顶部,和
plt.show()
at the end.
在末尾。
回答by jmz
In the IPython notebook you could also use %matplotlib inlineat the top of the notebook to automatically display the created plots in the output cells.
在 IPython 笔记本中,您还可以%matplotlib inline在笔记本顶部使用以在输出单元格中自动显示创建的图。
回答by Akash Nayak
your code is correct. just put:
你的代码是正确的。只是放:
import matplotlib as plt
for diplaying you plot:
用于显示您的情节:
plt.show()

