plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.11k stars 2.54k forks source link

Offline way to programmatically save graph as PNG? #483

Closed ghost closed 7 years ago

ghost commented 8 years ago

Hi, i am using plotly and like it.

I need to save graphs i created at server side as PNG images using plotly offline. Is there a way to do it?

yankev commented 8 years ago

@evrenkutar Currently the procedure in which we turn plots into static images requires communication with our servers.

jackparmer commented 8 years ago

@evrenkutar @yankev If you're using Jupyter notebook, you should be able to access this toImage() routine programmatically in Python: https://plot.ly/javascript/static-image-export/ @cldougl @yankev Can you please look at how the R client does this and add official support (and docs) for the Python client?

hyliu1989 commented 8 years ago

Chrome under Windows 10 is not working with image download (both programmatically and using mouse to click the camera thumbnail) It was run with the commit 9e52ce41753e52f8a1159ab177f04f9c015501d9. (17 Jun 2016 16:39) Maybe the offline js module should be synchronized with plotly.js since it has been fixed in plotly.js #604

yankev commented 8 years ago

@hyliu1989 Thanks for the reminder. We should be pushing a new version up on pip early next week.

cldougl commented 7 years ago

docs of offline image exporting can be found here: https://plot.ly/python/static-image-export/#export-static-image-offline

NicoHood commented 7 years ago

@cldougl This currently opens a web browser which requests to safe the picture. If you try to export multiple PNGs this is not really a usable way. It would be nice to directly export as PNG file from python. Could you please reopen this issue?

As a workaround I found this post which converts the data into matlab. However this did not work for me with the latest plotly version. https://stackoverflow.com/questions/40243446/how-to-save-plotly-offline-graph-in-format-png

bluprince13 commented 6 years ago

@cldougl, I second @NicoHood , a programmatic way of exporting images in offline mode would be really useful - particularly for the use case of needing to export multiple images. At the moment, it's a pain!

efayadspecific commented 6 years ago

yes, please!! I need to programmatically create heatmaps from 2000+ Pandas data frames. having each open up in a browser is not tractable, in my opinion. thanks!

jwhendy commented 6 years ago

Since this has the most unique users of issues requesting this (there are several), would anyone here be capable to implement something if the plotly team sketched a possible method?

As all of the closed issues suggest, they probably aren't going to do this... but perhaps we could. This was my pitch in the newest incantation of this request, #880 . Perhaps if you show your support via programming chops we can get a direction to take and collaborate?

bluprince13 commented 6 years ago

@jwhendy I hope something comes off this. I'm definitely willing to help, but I don't have any previous experience of contributing source code even in Python. JavaScript is something I've just started learning. So, may be limited in what I can do!

I do think this is a key feature that plotly is lacking, potentially even one that prevents a large population of data analysts from adopting plotly. I use plotly to probe all of my data since it's interactive, and then I have to use matplotlib to save them as plots to share with my colleagues because I'm generating hundreds of plots at a time!!

jwhendy commented 6 years ago

@bluprince13 see the most recent post at #880. I was able to make some progress on two potential methods. Feel free to try them out! I'm hoping @cldougl suggests a place one of them could fit in the library, and I'll make a pull request. Likely this will require someone more advanced than me to take a look and give input.

jackparmer commented 6 years ago

Update on this issue from Plotly: https://github.com/plotly/plotly.py/issues/880#issuecomment-354531041

eagleEggs commented 6 years ago

FYI this is now possible with one line after setting your data and figure:

edit [051518]: actually this doesn't work :/

data = Data([tasks, tasks2, tasks3]) fig = Figure(data=data, layout=layout) offline.iplot(fig, filename='graph', image='png')

It saves to the /Downloads directory.

https://gist.github.com/eagleEggs/c441ffa88a90a8a360d771fae3ba2d8e

Looking for a way to change that default directory currently...

ghost commented 6 years ago

Really need this

jonmmease commented 6 years ago

Update: Offline programmatic static image export support has been released in 3.2.0: See https://medium.com/@plotlygraphs/plotly-py-end-of-summer-updates-5422c98b9058