AttributeError: 'module' object has no attribute 'pyplot'

def plot_test2():
fig = matplotlib.pyplot.gcf()
df = ts.get_hist_data('600415', start='2016-04-01', end='2016-06-18')
with pd.plot_params.use('x_compat', True):
df.high.plot(color='r', figsize=(10, 4), grid='on')
df.low.plot(color='b', figsize=(10, 4), grid='on')
fig.savefig('graph.png')
 
上面的代码是生成 某个股票2016年从4月到6月的 最低价和最高价的 走势图。
运行时直接出现错误:
AttributeError: 'module' object has no attribute 'pyplot' 
 
但是matplotlib包已经安装了。 
 
已邀请:

李魔佛 - 公众号:可转债量化分析 【论坛注册:公众号后台留言邮箱】

赞同来自:

>>> import matplotlib
>>> matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
 
直接导入matplotlib是不够的,还需要直接导入 
import matplotlib.pyplot
然后运行就没有问题了。
 
常见国外的帖子: http://stackoverflow.com/questions/14812342/matplotlib-has-no-attribute-pyplot
 

要回复问题请先登录注册