Search code examples
pythonmatplotlibmpld3

image to html using mpld3


I am trying to export the html of a graph using mpld3

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')


Facing Issue as AttributeError: 'Line2D' object has no attribute 'canvas


Solution

  • Figured out the 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")
    

    You need to pass figure object to save_html