Use Plotly Offline To Generate Graphs As Images: 5 Answers
Use Plotly Offline To Generate Graphs As Images: 5 Answers
Products Search… 1 1
Home
Use plotly offline to generate graphs as images Ask Question
PUBLIC Asked 5 years, 3 months ago Active 1 year, 5 months ago Viewed 29k times
Questions
I am working with plotly offline and am able to generate an html file using
Tags The Overflow Blog
Users 15 plotly.offline.plot({"data": data, "layout": layout}) Podcast 333: From music to trading
cards, software is transforming curation…
FIND A JOB
It works great. The graph is generated correctly and the html file gets saved to my current directory. Level Up: Creative Coding with p5.js –
Jobs
part 7
Companies 6 What I want, though is, using plotly offline, is to have an image (.png, .jpg, etc.) file saved instead.
Featured on Meta
Am I on the right track? What do I need to do from here?
TEAMS
@JohnCH, thanks for the comment, but I couldn't clearly understand which folder the image file saved. –
Cloud Cho Aug 22 '19 at 21:21
52 people chatting
Add a comment
Python
7 mins ago - Kevin
5 Answers Active Oldest Votes
12 import plotly.offline
import plotly.graph_objs as go
While it sucks to have to open the browser, from a lot of reading around SO and the plotly forums, this is Related
the only/best way to do this with offline at the moment. – Hendy Dec 26 '17 at 17:15
4208 Which “href” value should I use for
Would you consider making this fully reproducible? Edit: deleted my suggestions/request and just did it for
JavaScript links, “#” or “javascript:void(0)”?
you. Feel free to change anything you want. Just thought it would let people try without being confused
about potential import/naming errors. – Hendy Dec 26 '17 at 17:16
1728 <button> vs. <input type=“button” />. Which
@LordK, where the image file saved? – Cloud Cho Aug 22 '19 at 22:27 to use?
1
1994 How to lazy load images in ListView in
Add a comment Android
8 https://plot.ly/python/static-image-export/
772 How to display Base64 images in HTML?
So a minimal example would be:
11 How to save Plotly Offline graph in format
png?
import plotly.plotly as py
2 python offline plotly saves the file always in
import plotly.graph_objs as go
default file name how to save in differrent
import numpy as np
name
N = 1000
random_x = np.random.randn(N) Hot Network Questions
random_y = np.random.randn(N)
What mega bloks set is this? I need help finding it
trace = go.Scatter(
Why is winning the NYC Democratic mayoral
x = random_x, primary currently widely seen as tantamount to
y = random_y, election?
mode = 'markers'
) How do I simulate the interaction between two
atoms?
data = [trace] What's up with diodes' datasheets?
Share Edit Follow answered Jan 27 '16 at 11:47 Are all stainless pans necessarily non stick?
2 What I was trying to accomplish was to not have to connect to the plotly server at all. This is to support How can I drill through hardened steel wrenches?
faster chart creation. I wanted a generated chart saved as an image file without opening the chart and
without involving the plotly server. I'm currently thinking there is no way to accomplish this. Additionally, I How may I calculate the bond length between two
don't want to use their javascript version because this chart code is not going to make it to the browser at atoms?
all, but rather a chart will be saved in a pdf behind the scenes. – Matt Cremeens Jan 28 '16 at 19:52 Redundancy
Ok, I guess there is hope for the future for you, since plotly offline has just been released. Maybe they will Under cmd.exe, how can "del *.tmp" be prevented
let us save offline in the future. – Benares Jan 29 '16 at 10:21 from deleting *.tmpl files?
It is now possible if you add Plotly's orca to your website @Matt. See here. You can make an image Does Polymorph break attunements with
without displaying it. – Wayne Jun 4 '19 at 20:22 prerequisites?
data = px.data.gapminder()
Question feed
data_canada = data[data.country == 'Canada']
fig = px.bar(data_canada, x='year', y='pop',
hover_data=['lifeExp', 'gdpPercap'], color='lifeExp',
labels={'pop':'population of Canada'}, height=400)
Yes, for saving the file as .png format simply do : plotly.offline.plot(fig, filename= output_filename + ".png")
– Shantanu Deshmukh Nov 16 '19 at 19:09
Nope that just generate an html file with the name output_filename.png.html – Prashant Kumar
Nov 17 '19 at 12:13
remove .html at the end and replace that with .png – Shantanu Deshmukh Nov 17 '19 at 22:06
@ShantanuDeshmukh and where this file will be saved? Actually i am using plotly.offline.iplot() –
Muhammad Mar 25 '20 at 13:42
Add a comment
one possibility using ipython notebook is to display the graph and then choose the option
"Download plot as png" manually.
0
Share Edit Follow answered Jan 26 '16 at 16:38
Benares
896 1 6 12
Except I don't want it displayed. The program is part of a website that generates the graphs as part of a
pdf that gets emailed to a client. Thanks for the response, by the way. – Matt Cremeens Jan 26 '16 at
17:29
Add a comment
-2 import plotly.plotly as py
# Generate the figure
trace = Bar(x=[1,2,3],y=[4,5,6])
data = [trace]
layout = Layout(title='My Plot')
fig = Figure(data=data,layout=layout)
1 Did you actually try this? It's not reproducible (you need plotly.graph_objs , which you likely
imported locally) and it isn't offline as the user requested. Running this yields PlotlyRequestError:
You must be authenticated to generate an image via json. – Hendy Dec 26 '17 at
17:12
Add a comment
Your Answer
Links Images Styling/Headers Lists Blockquotes Code HTML Tables Advanced help
Not the answer you're looking for? Browse other questions tagged python html image python-2.7
STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn Instagram
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Advertising Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Terms of Service
Disable Responsiveness Contact Us
Cookie Settings
site design / logo © 2021 Stack Exchange Inc; user contributions
Cookie Policy licensed under cc by-sa. rev 2021.4.27.39157