Dav*_*ang 9 matplotlib smtplib python-3.x
我想知道我是否可以通过smtplib发送matplotlib pyplot.我的意思是,在我绘制这个数据帧之后:
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>
Run Code Online (Sandbox Code Playgroud)
我知道我可以看到情节使用
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是对象本身存储在哪里?或者我误解了关于matplotlib的一些事情?有没有办法将它转换为python中的图片或html所以我可以通过smtplib发送它?谢谢!
Jor*_*nzo 22
也可以将内存中的所有内容保存到BytesIO缓冲区,然后使用它来提供有效负载:
buf = io.BytesIO()
plt.savefig(buf, format = 'png')
buf.seek(0)
mail = MIMEMultipart()
...
part = MIMEBase('application', "octet-stream")
part.set_payload( buf.read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % 'anything.png')
mail.attach(part)
Run Code Online (Sandbox Code Playgroud)
您可以使用figure.savefig()将绘图保存到文件.我将绘图输出到文件的示例:
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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8118 次 |
| 最近记录: |