【发布时间】:2023-04-11 01:56:01
【问题描述】:
我想将 python matplotlib 生成的图形嵌入到带有其他内容的 html 文件中。这可能吗?
我的想法是将数字保存为png文件,然后使用<img>标签来引用它。
我尝试使用的一些代码如下:
import matplotlib.pyplot as plt
fig = plt.figure()
#plot sth
plt.savefig('test.png')
html = 'Some html head' + '<img src=\'test.png\'>' + 'Some more html'
with open('test.html','w') as f:
f.write(html)
但是,这将生成两个文件而不是一个文件,而且我没有服务器来托管 png 文件。可以将图形嵌入到html中吗?我如何在 python 中做到这一点。
谢谢。
【问题讨论】:
-
使用 base64 图像怎么样? stackoverflow.com/questions/8499633/…
-
Outlook IOS 客户端不显示以 html 格式电子邮件进行 base64 编码的图像。有什么解决办法吗?
标签: python html matplotlib