I generate a plotly graph using this:
import plotly.plotly as py
import plotly.graph_objs as go
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='stacked-bar')
I tried generating a pdf using:
from xhtml2pdf import pisa
result_file = open('report.pdf', "w+b")
pisa_status = pisa.CreatePDF(
url,
dest=result_file)
result_file.close()
But I end up getting a pdf file with the url on it instead of the graph.
How can I export the plotly graph into a pdf? One the webpage, when I click the export button I am able to generate a jpeg and png but not a pdf. Also, I'm unable to control the size of the graph when exporting the, how can I control the size? Stretch out the graph making it a little wider.
Thanks.
The APIs have now changed, so I thought I'd post an update..
The new way of doing it is to use plotly.io.write_image
Here is an example:
plotly.io.write_image(fig, 'output_file.pdf', format='pdf')
The following formats are supported: png, jpg (or jpeg), webp, svg, pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With