'Python Plotly image how to save image to a iobuffer and read it back
Python Matplotlib image is saved like :
img = io.BytesIO()
plt.savefig(img, format='png')
img.seek(0)
encoded = base64.b64encode(img.getvalue())
but for plotly image the same code showing error like:
AttributeError: 'Figure' object has no attribute 'figure'
Any solution for this?
Solution 1:[1]
io.BytesIO has a function write().
img = io.BytesIO()
fig_svg = fig.to_image(format="svg") # kaleido library
img.write(fig_svg)
img.seek(0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | maxim |