簡體   English   中英

如何從使用 Texthero 生成的 wordcloud 中保存圖像文件

[英]How to save a image file from a wordcloud generated with Texthero

這是我的代碼-但是它保存了一個空文件-在此先感謝您的幫助。

df['Text_cleaned'] = hero.clean(df['Text'])

with open('wordcloud.jpg', 'w') as f:
    print(hero.wordcloud(df.Text_cleaned, max_words=50), file=f)

我在 Flask 應用程序中工作,我需要在回復中以 png 格式返回圖像。 我的代碼會給傳入的請求返回一個圖像,您可以根據您的要求對其進行造型。 hero.wordcloud 接受可選參數 return_figure,您需要將其設置為 true。

ax=hero.wordcloud(Kto['new'], max_words=200, height=400, width=600,return_figure=True)
plt.figure(figsize=(18, 12))
img = ax.get_figure()
output = io.BytesIO()
FigureCanvas(img).print_png(output)
return Response(output.getvalue(), mimetype='image/png')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM