'How to save the plot in image format
Here 'graphJSON' is a variable used for plotting the graph and how can i capture(image format) the graph using this variable?
graphJSON = json.dumps(data, cls=plotly.utils.PlotlyJSONEncoder)
plotly.io.to_image(graphJSON, format=None,
scale=None, width=None, height=None)
Solution 1:[1]
The marked answer is correct. This is just an FYI that you can simplify the fig to png_base64 conversion by converting the figure directly to an image.
This:
png_base64 = base64.b64encode(fig.to_image()).decode('ascii')
Instead of this:
# convert graph to JSON
fig_json = fig.to_json()
# convert graph to PNG and encode it
png = plotly.io.to_image(fig)
png_base64 = base64.b64encode(png).decode('ascii')
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 | cyotani |
