no output with numpy/matlibplot

103 views
Skip to first unread message

koldito

unread,
Mar 24, 2012, 1:43:20 PM3/24/12
to nltk-users
I'm working my way through the first chapter of the NLTK book. I'm
trying to produce the dispersion and cumulative frequency plots,
following the instructions:

>>> import nltk
>>> import numpy
>>> import matplotlib
>>> from nltk.book import *
[various normal lines of output]
>>> text4.dispersion_plot(["citizens", "democracy"])

...and then, nothing. No error message, no output of any sort, just a
new >>> prompt. I am running Python 2.7 on Ubuntu 11.04, and I'm
pretty sure I have installed numpy and matplotlib correctly (or at
least, I don't get any error messages when I import them). I'm running
it from a terminal window, but I've also tried on IDLE and I get
exactly the same result.

Every other piece of code that I try that doesn't produce a graphic
output works fine.

Thanks.

SJ

unread,
Mar 24, 2012, 3:09:06 PM3/24/12
to nltk-...@googlegroups.com
I'd try putting all of this in a simple py script file and run it with --verbose-helpful option to see if matplotlib is loading correctly and what exactly is it trying to do.

Gus

unread,
Mar 24, 2012, 6:55:30 PM3/24/12
to nltk-...@googlegroups.com
This is my first mailing to the group.  

Alright, I think I might be able to help as I ran into a similar problem when I first tried to use .plot()

My guess is you might have multiple versions of something installed and your path is not pointing nltk to the right place. 

This is what worked for me...
First, make sure that you have numpy, matplotlib, and their dependencies up-to-date on your machine.

If you're using pip try this using this command at the Unix terminal:

sudo pip install numpy --upgrade

just replace numpy with the name of the other packages you need to upgrade.

Since you're doing this housekeeping, you might want to upgrade nltk at the end of this process.

Now that that's taken care of...

1. Open up IDLE or iPython (you can do this from the terminal, if you want).
2. At the interpreter prompt, import the following:

from nltk.book import *

3.  Now for the moment of truth.  Try something simple like:

FreqDist(text3).plot(20)

Did it work? 
You can try adding cululative=True, changing 20 to some other number, and switching the argument for FreqDist.   

Hope that helps,

--Gus

koldito

unread,
Mar 26, 2012, 8:40:49 AM3/26/12
to nltk-users
Following Gus' suggestion, I've removed and reinstalled nltk, numpy,
and matplotlib, and now everything works properly. I wish I could be
of more help and detail exactly what wasn't working previously.

Luis

On Mar 25, 12:55 am, Gus <lastwordwiz...@gmail.com> wrote:
> This is my first mailing to the group.
>
> Alright, I think I might be able to help as I ran into a similar problem
> when I first tried to use .plot()
>
> My guess is you might have multiple versions of something installed and
> your path is not pointing nltk to the right place.
>
> This is what worked for me...
> First, make sure that you have numpy, matplotlib, and their dependencies
> up-to-date on your machine.
>
> If you're using pip <http://pypi.python.org/pypi/pip> try this using this
> command at the Unix terminal:
>
> sudo pip install numpy --upgrade
>
> just replace numpy with the name of the other packages you need to upgrade.
>
> Since you're doing this housekeeping, you might want to upgrade nltk at the
> end of this process.
>
> Now that that's taken care of...
>
> 1. Open up IDLE or iPython <http://ipython.org/> (you can do this from the
Reply all
Reply to author
Forward
0 new messages