【发布时间】:2017-10-28 01:57:54
【问题描述】:
我正在使用 python3 中的 wordcloud 模块并尝试保存一个应该只给我 wordcloud 的图像而云周围没有任何空格的图形。我尝试了 stackexchange 中提到的许多滴答声,但没有奏效。下面是我的默认代码,它可以去掉左右两边的空格,但不能去掉顶部和底部的空格。如果我将 ax = plt.axes([0,0,1,1]) 中的其他两个值也设为 0,那么我会得到一个空图像。
wordcloud = WordCloud(font_path=None, width = 1500, height=500,
max_words=200, stopwords=None, background_color='whitesmoke', max_font_size=None, font_step=1, mode='RGB',
collocations=True, colormap=None, normalize_plurals=True).generate(filteredText)
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes([0,0,1,1])
plt.imshow(wordcloud, interpolation="nearest")
plt.axis('off')
plt.savefig('fig.png', figsize = (1500,500), dpi=300)
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: python matplotlib word-cloud