使用mpld3将图像转换为html

2024-10-06 12:08:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用mpld3导出图形的html

import matplotlib.pyplot as plt, mpld3
obj, = plt.plot([3,1,4,1,5], 'ks-', mec='w', mew=5, ms=20)
mpld3.save_html(obj,'C:\\Users\\prabhat.mishra\\Desktop\\figure.html')


面临的问题是AttributeError: 'Line2D' object has no attribute 'canvas


Tags: importobj图形plotmatplotlibsavehtmlas
1条回答
网友
1楼 · 发布于 2024-10-06 12:08:30

找到了solution

import matplotlib.pyplot as plt, mpld3
fig = plt.figure()
obj, = plt.plot([3,1,4,1,5])
mpld3.save_html(fig,"C:\\Users\\prabhat.mishra\\Desktop\\figure1.html")

您需要将figure对象传递给save_html

相关问题 更多 >