我正在尝试将pyplot图保存为png
import matplotlib.pyplot as plt
# take relative word frequencies into account, lower max_font_size
wordcloud = WordCloud(max_font_size=40, relative_scaling=.5).generate(text)
fig = plt.figure()
fig.savefig("../../results/plots/"+wf+".png")
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
plt.close()
图表显示正确,但始终存储空图像。我的语法有问题吗?
答案 0 :(得分:2)
fig = plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
fig.savefig("../../results/plots/"+wf+".png")
plt.show()
plt.close()
我在绘图之前试图保存