# How to change plot size in nltk.plot()

I'm following along the NLTK book and would like to change the size of the axes in a lexical dispersion plot:

import nltk
from nltk.corpus import inaugural
cfd = nltk.ConditionalFreqDist(
(target, fileid[:4]) # "[:4]" slices only the years of the speeches
for fileid in inaugural.fileids()
for word in inaugural.words(fileid)
for target in ["liberty", "equality", "brotherhood"]
if word.lower().startswith(target))


Because it gets very crowded otherwise:

cfd.plot(title="French ideals in US-American speeches through time") the __doc__ doesn't seem to mention it:

print(cfd.plot.__doc__)

Plot the given samples from the conditional frequency distribution.
For a cumulative plot, specify cumulative=True.
(Requires Matplotlib to be installed.)

:param samples: The samples to plot
:type samples: list
:param title: The title for the graph
:type title: str
:param conditions: The conditions to plot (default is all)
:type conditions: list


And I think there is nothing on it in the NLTK documentation, but also not in the matplotlib documentation (where I figured the plot functionality comes from):

http://www.nltk.org/py-modindex.html#cap-p
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot


(sorry for the code-block links, I'm new here and can't post more than 2 links but still felt like making it easier for someone reading this :)

I'd be glad if someone could point me into the right direction! Thanks!

• Try creating a figure of appropriate size before calling plot().
– Emre
Jan 20 '17 at 21:21
• Hei @Emre, thanks for your answer. nltk.ConditionalFreqDist() does not have a .figure() method, and in the code (check out line 1781) I found that .plot() doesn't accept any figure-size related **kwargs (from what I can tell, but that's also what the pyplot.plot() documentation seems to suggest..?). After reading nltk's code, I added linewidth=1, which makes the lines a bit slimmer, but the original issue remains. Jan 21 '17 at 23:55

import matplotlib.pyplot as plt