Black Lives Matter. Please consider donating to Black Girls Code today.

Downloading plots with custom resolution and format

Hi,
I am new to Python and Dash and have been enjoying the experience so far. I come from using Matlab GUIDE, and really like the aesthetics in Dash. I am trying to save image to the disk from the ‘Save Image as png’ in the modebar.

  1. Is there a way to save the image in a higher resolution than the display resolution? I would like to use vh to define the size of the plot. I would like to export it at a specified aspect ratio and resolution.

  2. Is there a way to export as pdf as of now?

  3. Is there a way to programmatically trigger export of the graphs as png?

  4. It appears that Plotly.js has Plotly.toImage() to specify resolution and format. Can this be used in Python? (Sorry if this is a noob question)

Thanks!!!

These options are available through the plot.ly service (image and PDF generation is server side, not portable to the client libraries). There are two ways to access this:

  1. Click the “Save and edit in cloud” button in the toolbar of a graph. This will open the graph in the Chart Studio interface. If you save the graph to your plotly account, then you can export it to PDF, EPS, and PNG at different resolutions and sizes. Note that that this requires a paid subscription if your data is private.
  2. Use the Python API to programatically generate these images through the server. You’ll need a https://plot.ly account and an API key since this is generating the images and PDFs on the server: https://plot.ly/python/static-image-export/

This doesn’t do export to other formats besides PNG, PDF and EPS export require a variety of software packages to do reliably and is only available by Plotly through the API or the web service currently.

I see. Thank you. Is there a way to be able to programmatically generate these images offline (either paid/free)?

Never mind. I figured it out. But looks like it is going to open a html file everytime the plot is exported offline. Thank you! Great application! Loving it!

1 Like

Hi Chris

I’ve got formal question related to using Python API for programatically generating images through the server. As you pointed out, “You’ll need a Plot.ly account”. Mind that these are personal accounts.
So, how about using this export feature in a webapp used by several people?
Is it still aligned with https://plot.ly/terms-of-service/?

To give you a context, I’m going to prepare a dashboard with several simple graphs + “Download to PDF” button. Following the tutorial https://plot.ly/python/pdf-reports/ I need to convert charts to PNG files first.

Is there a way to be able to programmatically generate these images offline (either paid/free)?

Thanks! Great work.