【发布时间】:2018-10-16 16:34:03
【问题描述】:
当我通过 SSH(使用 -X)进入我的 Ubuntu 16.04 服务器并运行此脚本时,我收到了 _tkinter.TclError: couldn't connect to display "localhost:10.0"
from os import path
from wordcloud import WordCloud
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use('Agg')
d = path.dirname(__file__)
text = open(path.join(d, 'words.txt')).read()
wordcloud = WordCloud().generate(text)
# Configure plot
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
# lower max_font_size
wordcloud = WordCloud(max_font_size=40).generate(text)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.savefig("comments.png")
此脚本正在使用 Wordcloud (https://github.com/amueller/word_cloud/)。 words.txt 是一堆我打算变成 wordcloud 的词。应该发生的事情是云在我要进入的服务器上保存为 cmets.png(但不显示)。
【问题讨论】:
标签: python-3.x ubuntu