[docs]defplot_words(word_counts,n=10):"""Plot a bar chart of word counts. Parameters ---------- word_counts : collections.Counter Counter object of word counts. n : int, optional Plot the top n words. By default, 10. Returns ------- matplotlib.container.BarContainer Bar chart of word counts. Examples -------- >>> from pycounts.pycounts import count_words >>> from pycounts.plotting import plot_words >>> counts = count_words("text.txt") >>> plot_words(counts) """top_n_words=word_counts.most_common(n)word,count=zip(*top_n_words)plt.bar(range(n),count)plt.xticks(range(n),labels=word,rotation=45)plt.xlabel("Word")plt.ylabel("Count")returnplt.gcf()