Python Matplotlib到smtplib [英] Python Matplotlib to smtplib
本文介绍了Python Matplotlib到smtplib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以通过smtplib发送一个matplotlib pyplot.我的意思是,在绘制此数据框之后:
I'm wondering if I can send out a matplotlib pyplot through smtplib. What I mean is, after I plot this dataframe:
In [3]: dfa
Out[3]:
day imps clicks
70 2013-09-09 90739468 74609
69 2013-09-08 90945581 72529
68 2013-09-07 91861855 70869
In [6]: dfa.plot()
Out[6]: <matplotlib.axes.AxesSubplot at 0x3f24da0>
我知道我可以使用
plt.show()
但是对象本身存储在哪里?还是我对matplotlib有误解?有没有一种方法可以在python中将其转换为图片或html,以便我可以通过smtplib发送它?谢谢!
but where is the object itself stored? Or am I misunderstanding something about matplotlib? Is there a way to convert it to a picture or html within python so I can send it through smtplib? Thanks!
推荐答案
You can use figure.savefig()
to save your plot to a file. An example where I output a plot to a file:
fig = plt.figure()
ax = fig.add_subplot(111)
# Need to do this so we don't have to worry about how many lines we have -
# matplotlib doesn't like one x and multiple ys, so just repeat the x
lines = []
for y in ys:
lines.append(x)
lines.append(y)
ax.plot(*lines)
fig.savefig("filename.png")
然后将图像附加到您的电子邮件中(例如此答案中的食谱).
Then just attach the image to your email (like the recipe in this answer).
这篇关于Python Matplotlib到smtplib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文