如何导入matplotlib.pyplot

时间:2012-02-11 10:34:55

标签: python matplotlib

我试图在IDLE上运行以下example code,这是从matplotlib官方网站复制的:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

但是我遇到了很多错误:

Traceback (most recent call last):
  File "D:/temp/pyplot_test.py", line 2, in <module>
    import matplotlib.pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 23, in <module>
    from matplotlib.figure import Figure, figaspect
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 18, in <module>
    from axes import Axes, SubplotBase, subplot_class_factory
  File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 14, in <module>
    import matplotlib.axis as maxis
  File "C:\Python27\lib\site-packages\matplotlib\axis.py", line 12, in <module>
    import matplotlib.patches as mpatches
  File "C:\Python27\lib\site-packages\matplotlib\patches.py", line 1615, in <module>
    class BoxStyle(_Style):
  File "C:\Python27\lib\site-packages\matplotlib\patches.py", line 2068, in BoxStyle
    {"AvailableBoxstyles": _pprint_styles(_style_list)}
  File "C:\Python27\lib\site-packages\matplotlib\patches.py", line 1539, in _pprint_styles
    args, varargs, varkw, defaults =  inspect.getargspec(cls.__init__)
AttributeError: 'module' object has no attribute 'getargspec'

我的电脑是Windows XP机器。 Python和matplotlib(以及其他网站包,如numpy)使用Python(x,y)干净地安装。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

尝试导入matplotlib.pylab,因为它是pyplot的别名。