There is an easy way to generate word frequency plots with NLTK:
my_plot = nltk.FreqDist(some_dynamically_changing_list[0]).plot(20)
some_dynamically_changing_list
contains a list of texts that I want to see the word frequency for. The resulting my_plot
is an AxesSubplot
object. I want to be able to take this object and directly insert it to a dynamically sized subplotted grid. The closest I've gotten to the solution after scouring SO and Google is this. However, I have an issue because I don't want to use plt's plot
function. So for example I'd have a dynamic subplot grid:
import matplotlib.pyplot as plt
tot = len(some_dynamically_changing_list)
cols = 5
rows = tot // cols
if tot % cols != 0:
rows += 1
position = range(1, tot + 1)
fig = plt.figure()
for k in range(tot):
ax = fig.add_subplot(rows, cols, position[k])
my_plot = nltk.FreqDist(some_dynamically_changing_list[k]).plot(20)
ax.plot(my_plot) #This is where I have my issue.
Of course this won't work, as ax.plot
expects data, not a plot. But I want to plug my my_plot
into that specific slot. How can I do that (if I can)?