matplotlib基本问题

发布于 2024-11-06 10:45:54 字数 1574 浏览 0 评论 0原文

请原谅我简单的问题。我刚刚开始使用 Matplotlib,但遇到了一些困难。

我可以使用解释器毫无问题地运行以下代码:

>>> from pylab import *  
>>> plot([1,2,3])  
>>> show()  

上面的代码生成了一个漂亮的图表。

但是,如果我将以下代码放入文件中并运行它,则会收到错误:

#!/usr/bin/env python
# encoding: utf-8

import sys
import os
from pylab import *

plot([1,2,3])
show()

这是错误消息:

Traceback (most recent call last):
  File "/Users/sbrown/Desktop/new1.py", line 12, in <module>
    from pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 133, in <module>
    from matplotlib.rcsetup import (defaultParams,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
    from matplotlib.colors import is_color_like
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py", line 54, in <module>
    import matplotlib.cbook as cbook
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py",     line 15, in <module>
    import new
  File "/Users/sbrown/Desktop/new.py", line 2, in <module>
    plot([1,2,3])
NameError: name 'plot' is not defined
>>> 

知道问题可能是什么吗?预先感谢您提供的任何帮助!

Please forgive my simple question. I have just started to use Matplotlib and I am having some difficulty.

I can run the following with the interpretor without problems:

>>> from pylab import *  
>>> plot([1,2,3])  
>>> show()  

The above code generates a beautiful graph.

However, if I place the following code inside a file and run it, I get an error:

#!/usr/bin/env python
# encoding: utf-8

import sys
import os
from pylab import *

plot([1,2,3])
show()

Here is the error message:

Traceback (most recent call last):
  File "/Users/sbrown/Desktop/new1.py", line 12, in <module>
    from pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 133, in <module>
    from matplotlib.rcsetup import (defaultParams,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
    from matplotlib.colors import is_color_like
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py", line 54, in <module>
    import matplotlib.cbook as cbook
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py",     line 15, in <module>
    import new
  File "/Users/sbrown/Desktop/new.py", line 2, in <module>
    plot([1,2,3])
NameError: name 'plot' is not defined
>>> 

Any idea what the problem could be? Thanks in advance for any help you can provide!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-11-13 10:45:54

看起来您的桌面上有一个文件正在隐藏标准 Python new 模块:

>>> import new
>>> new
<module 'new' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/new.pyc'>

重命名或删除 $HOME/Desktop/new.py 然后重试。

Looks like you have a file on your Desktop that is shadowing the standard Python new module:

>>> import new
>>> new
<module 'new' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/new.pyc'>

Rename or remove $HOME/Desktop/new.py and try again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文