Pytho Plotly save graphics with width and hight in mm or cm or inch

I save a plotly plot to a pdf. How can I set the size of the plot in mm or inch? The plot size and the grid has to match a certain length.

I absolutely cant wrap my head around logic Pixel and so forth.

import as pio
pio.write_image(fig_, “plot.pdf”,width=1000, height=800) #how to put units here

In ggplot it would look something like
ggsave(“filename.pdf”, plot = last_plot(), width = 5, height = 5, units = “in”)

Hi @bokken,

I just added a comment on an open orca issue that has a formula for specifying PDF dimensions in inches. See Hopefully we’ll work out a simpler way to support this in the future, but I hope this helps in the meantime!


This is great. I tried the solution there and it almost works for me. However, there are two problems:

(i) After every graph, there is a blank page. I am using landscape mode.
(ii) The page size is still not exactly the same as that created by matplotlib and pdfpages, despite using 20" and 12" for width and height. It’s very close however. I assume that either the ppi number is slightly out, or, more likely, the pdf dimensions have been rounded to the nearest ".

I’m not sure that (ii) matters, but (i) is a biggie. Perhaps I can fix by tinkering with my output plot resolution …