我在ubuntu 14.04 LTS中使用pip安装了matplotlib
但是在运行dispersion_plot
时显示以下错误..
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/text.py", line 455, in dispersion_plot
from nltk.draw import dispersion_plot
ImportError: cannot import name dispersion_plot
我是python的新手...任何人都可以建议在matplotlib
中安装nltk
的方法是否更好。
答案 0 :(得分:11)
在线图书的例子并不完全正确。
你可以试试这个:
from nltk.draw.dispersion import dispersion_plot
words = ['Elinor', 'Marianne', 'Edward', 'Willoughby']
dispersion_plot(gutenberg.words('austen-sense.txt'), words)
您也可以直接从文本中调用它:
from nltk.book import text1
from nltk.draw.dispersion import dispersion_plot
dispersion_plot(text1, ['monstrous'])
这样你直接导入函数而不是从文本对象调用funcion。 我意识到这直接看源代码。
希望这对你有用
答案 1 :(得分:0)