【发布时间】:2020-10-24 13:43:51
【问题描述】:
我有一个 python 脚本,可以将 histogram 和 wordcloud 绘制在 2 个单独的图中。
我想要的是将这两个结果绘制成一个数字。
代码:
#plot word count distribution for both positive and negative sentiment
x= def_test_twtr_preds["processed word count"][def_test_twtr_preds.predictions ==1]
y= def_test_twtr_preds["processed word count"][def_test_twtr_preds.predictions ==0]
fig1 = plt.figure(figsize=(12,6))
plt.xlim(0,45)
plt.xlabel("word count")
plt.ylabel("frequency")
g = plt.hist([x,y],color=["r","b"],alpha=0.5,label=["positive","negative"])
plt.legend(loc="upper left")
# splt sentence to get individual words
all_words=[]
for line in def_test_twtr_preds["tokens"]:
all_words.extend(line)
#create a word frequency dictionary
wordfreq = Counter(all_words)
# #draw a word cloud with word frequencies
wordcloud = WordCloud(width=900,
height = 500,
max_words=500,
max_font_size=100,
relative_scaling=0.5,
colormap="Blues",
normalize_plurals=True).generate_from_frequencies(wordfreq)
fig2 = plt.figure(figsize=(17,14))
plt.imshow(wordcloud,interpolation="bilinear")
plt.axis("off")
plt.show()
【问题讨论】:
标签: python matplotlib histogram word-cloud