开发者

matplotlib basic question

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/P开发者_如何学Cython.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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜