Dispersion_plot does not work despite setting matplotlib

I installed matplotlibpip with ubuntu 14.04 LTS .. but the dispersion_plotfollowing error is displayed on startup .

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'm new to python ... can anyone suggest if there is a better way to install matplotlibin nltk.

+4
source share
1 answer

Examples of online books are not entirely correct.

You can try the following:

from nltk.draw.dispersion import dispersion_plot

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

You can also call it directly from the text:

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

dispersion_plot(text1, ['monstrous'])

this way you import the function directly, rather than calling funcion from a text object. I realized that I was looking directly at the source code.

Hope this work for you

+8
source

All Articles