如何在python中导入matplotlib

如何在python中导入matplotlib

问题描述:

我是python的新手,正在研究一个图形问题,我想绘制此图形以更好地理解它.我了解到应该为此导入matplotlib模块,但我不知道如何将其添加到项目中.(我是一名Java开发人员,这很像将jar添加到您的类路径中)

I am new to python and I am working on a graph problem and I want to draw this graph to have a better understanding of it. I learnt that matplotlib module is supposed to be imported for this but I dont know how to add it to the project.(I am a java developer and It is pretty much like adding jar to your classpath)

当我尝试做

import matplotlib

我收到以下错误:

File "/Library/Python/2.7/site-packages/networkx-1.7rc1-py2.7.egg/networkx/drawing/nx‌​_pylab.py", line 114, in draw
    raise ImportError("Matplotlib required for draw()")
ImportError: Matplotlib required for draw()
ImportError: No module named matplotlib.pyplot

有人可以帮助我吗?我需要下载任何内容以使其在模块中运行吗?

Can anyone help me with that?Do I need to download anything to make it run as in the module?

模块:new

module: new

正如David Robinson在对另一个答案的评论中指出的那样,您可能发布了不完整的错误消息,在这种情况下,内置模块new可能被gis模块中的new.py遮盖了. -如果是这种情况,则建议的修补程序是重命名gis版本.

As David Robinson points out in a comment on another answer you may have posted an incomplete error message, in which case it is possible that the inbuilt module new is being shadowed by new.py in the gis module. - if that is the case the suggested fix is to rename the gis version.

Matplotlib安装不完整

或者,考虑到您的输出,您可能正在尝试导入networkx,而您似乎没有(正确)安装了matplotlib.

Alternatively, given your output you may be trying to import networkx and you don't seem to have matplotlib (correctly) installed.

如果您使用

sudo apt-get install python-matplotlib

,或者如果您更喜欢pipeasy_install

or if you prefer pip or easy_install,

pip install matplotlib

easy_install matplotlib