简体   繁体   English

如何导入matplotlib.pyplot

[英]how to import matplotlib.pyplot

I tried to run, on IDLE, the following example code , which was copied from matplotlib's official website: 我尝试在IDLE上运行以下示例代码 ,该代码是从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)

But I got lots of errors: 但是我有很多错误:

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'

My computer is a Windows XP machine. 我的计算机是Windows XP计算机。 Python and matplotlib (and other site packages such as numpy) were installed cleanly using Python(x,y) . 使用Python(x,y)干净安装了Python和matplotlib(以及其他站点软件包,例如numpy Any idea how to resolve this issue? 任何想法如何解决这个问题?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM