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")

enter image description here

the __doc__ doesn't seem to mention it:


        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):


(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!

  • $\begingroup$ Try creating a figure of appropriate size before calling plot(). $\endgroup$ – Emre Jan 20 '17 at 21:21
  • $\begingroup$ 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. $\endgroup$ – martin-martin Jan 21 '17 at 23:55

Try something like this:

import matplotlib.pyplot as plt
plt.figure(figsize=(30, 20))  # the size you want

# your code goes here
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.