如何在 nltk.plot() 中更改绘图大小

数据挖掘 Python nlp nltk 朱庇特 蟒蛇
2021-10-10 04:27:09

我正在关注 NLTK 书,并希望在词汇分散图中更改轴的大小:

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

因为否则它会变得非常拥挤

cfd.plot(title="French ideals in US-American speeches through time")

在此处输入图像描述

__doc__似乎没有提到它

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

而且我认为 NLTK 文档中没有任何内容,但 matplotlib 文档中也没有(我认为绘图功能来自哪里):

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

(对不起代码块链接,我是新来的,不能发布超过 2 个链接,但仍然觉得让阅读本文的人更容易:)

如果有人能指出我正确的方向,我会很高兴!谢谢!

1个回答

尝试这样的事情:

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

# your code goes here