Python NLTK: fdist.plot error - python

I am trying to make a plot of frequencies for the top 50 words from a text file but this is the error message I am getting.
s-10', 'logan', 'jacksonville', 'brokerage', 'brickman', 'mount', 'wireless', 'p
hillips', 'advisor', 'okavango', 'portfolio', 'sill', 'weddings', 'share', 'para
legal']
>>> fdist1.plot(50)
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\nltk\probability.py", line 229, in plot
import pylab
ImportError: No module named 'pylab'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\nltk\probability.py", line 231, in plot
raise ValueError('The plot function requires the matplotlib package (aka pyl
ab). '
ValueError: The plot function requires the matplotlib package (aka pylab). See h
ttp://matplotlib.sourceforge.net/
My professor's sample code does not say anything about importing a pylab package. I tried to download it anyways and it still doesn't seem to be working.
Any help is appreciated :)
Thanks

Plotting a distribution requires matplotlib.
See the relevant lines of FreqDist.plot():
try:
from matplotlib import pylab
except ImportError:
raise ValueError('The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/')

Related

Python and matplotlib: when I try to import, it send a not valid cycler construction error

I've wanted to try matplotlib for the first time but when I import it, there is an error.
The only line of my code is:
from matplotlib import pyplot as plt
but when I run this, I have this error:
Traceback (most recent call last):
File "/Users/mylaptop/Desktop/main.py", line 1, in <module>
from matplotlib import pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 903, in <module>
rcParamsDefault = _rc_params_in_file(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 834, in _rc_params_in_file
config[key] = val # try to convert to proper type or raise
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/matplotlib/__init__.py", line 678, in __setitem__
raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key axes.prop_cycle: 'cycler('color', ['1f77b4', 'ff7f0e', '2ca02c', 'd62728', '9467bd', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])' is not a valid cycler construction: name 'np' is not defined
I have no idea on how to fix it.
I am on Mac and I use the Pycharm IDE.
Looking at the code of matplotlib/__init__.py, the Python library numpy is a requirement of matplotlib, but the error:
name 'np' is not defined
seems to tell us that it's not (correctly) installed in your system.

dir(sns) not listing plt

I am trying to use `dir(sns.plt) but this results in an error:
dir(sns.plt)
Traceback (most recent call last):
File "<ipython-input-3-8072046646b0>", line 1, in <module>
dir(sns.plt)
AttributeError: module 'seaborn' has no attribute 'plt'
How do get 'plt' to show up or add it?
Please review this posting for more information on plt used with seaborn:
Seaborn plots not showing up

Tifffile.imshow() KeyError: 'matplotlib.pyplot'

I used the Tifffile module's imshow () method to display the tiff image in Python 3.5.2.
The code is as follows:
import tifffile as tiff
IM_ID = '6120_2_2'
im_rgb = tiff.imread('/home/roy/image&csv/image/{}.tif'.format(IM_ID)).transpose([1, 2, 0])
im_size = im_rgb.shape[:2]
tiff.imshow(im_rgb)
But there is an error:
Traceback (most recent call last):
File "/home/roy/PycharmProjects/CSV2Ploy/csv2ploy.py", line 49, in <module>
tiff.imshow(im_rgb)
File "/usr/local/lib/python3.5/dist-packages/tifffile/tifffile.py", line 6349, in imshow
pyplot = sys.modules['matplotlib.pyplot']
KeyError: 'matplotlib.pyplot'
I think it must be my development environment missing the matplotlib.pyplot module. So I checked the matplotlib directory, but found that the directory does have pyplot.py file.
The terminal queries the pyplot.py file
I have a lot of information on the Internet, but most are import matplotlib.pyplot problems, some people can help me solve this problem?

matplotlib python3.4.1 win7

I am using python3.4.1 in win7
And I wana use matplotlib.
but this error code has occured.
Could you help me?
>>> text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\nltk\draw\dispersion.py", line 25, in dispersion_plot
import pylab
File "C:\Python34\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python34\lib\site-packages\matplotlib\__init__.py", line 105, in <module>
import six
ImportError: No module named 'six'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
File "C:\Python34\lib\site-packages\nltk\text.py", line 445, in dispersion_plot
dispersion_plot(self, words)
File "C:\Python34\lib\site-packages\nltk\draw\dispersion.py", line 27, in dispersion_plot
raise ValueError('The plot function requires the matplotlib package (aka pylab).'
ValueError: The plot function requires the matplotlib package (aka pylab).See
http://matplotlib.sourceforge.net/
>>>

Why scipy.io.wavfile.read does not return a tuple?

I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...

Categories