小编use*_*366的帖子

matplotlib将数字嵌入自动生成的html中

我想将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)
Run Code Online (Sandbox Code Playgroud)

但是,这将生成两个文件,而不是一个,并且我没有服务器来托管png文件。可以将图形嵌入html吗?我如何在python中做到这一点。

谢谢。

html python matplotlib

9
推荐指数
1
解决办法
8438
查看次数

标签 统计

html ×1

matplotlib ×1

python ×1