matplotlib没有属性'pyplot' [英] matplotlib has no attribute 'pyplot'

查看:1120
本文介绍了matplotlib没有属性'pyplot'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以导入matplotlib,但是当我尝试运行以下命令时:

I can import matplotlib but when I try to run the following:

matplotlib.pyplot(x)

我得到:

Traceback (most recent call last):
   File "<pyshell#31>", line 1, in <module>
       matplotlib.pyplot(x)
AttributeError: 'module' object has no attribute 'pyplot'

推荐答案

matplotlib的子模块,无法通过简单的import matplotlib导入.

pyplot is a sub-module of matplotlib which doesn't get imported with a simple import matplotlib.

>>> import matplotlib
>>> print matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
>>> import matplotlib.pyplot
>>> 

这似乎很常见:import matplotlib.pyplot as plt此时,您可以使用其中包含的各种函数和类:

It seems customary to do: import matplotlib.pyplot as plt at which time you can use the various functions and classes it contains:

p = plt.plot(...)

这篇关于matplotlib没有属性'pyplot'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆