Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dispersion_plot not working inspite of installing matplotlib

i have installed matplotlib using pip in ubuntu 14.04 LTS.. but on running dispersion_plot this is showing the following error ..

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

I am new to python... can anyone suggest if there is a better way of installing matplotlib in nltk.

like image 310
lazarus Avatar asked Aug 07 '14 12:08

lazarus


1 Answers

The examples of the online book are not quite right.

You may try this:

from nltk.draw.dispersion import dispersion_plot

words = ['Elinor', 'Marianne', 'Edward', 'Willoughby']
dispersion_plot(gutenberg.words('austen-sense.txt'), words)

You may also call it from a text directly:

from nltk.book import text1
from nltk.draw.dispersion import dispersion_plot

dispersion_plot(text1, ['monstrous'])

this way you import the function directly instead of calling the funcion from text object. I realized this watching at the source code directly.

Hope this work for you

like image 59
sandino Avatar answered Nov 14 '22 20:11

sandino