0% found this document useful (0 votes)
376 views1 page

Use Plotly Offline To Generate Graphs As Images: 5 Answers

Plotly Offline

Uploaded by

vaskore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
376 views1 page

Use Plotly Offline To Generate Graphs As Images: 5 Answers

Plotly Offline

Uploaded by

vaskore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

1

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

New onboarding for review queues


Stack Overflow for python html image python-2.7 plotly
Teams – Collaborate Should questions about obfuscated code
and share knowledge be off-topic?
with a private group. Share Edit Follow asked Jan 22 '16 at 23:41
Matt Cremeens Hot Meta Posts
4,631 6 29 58

13 Another set of eyes on my closed-but-


answered question?
2 I would fall back to Matplotlib (just mentioning it in case you didn't know the lib) – Maximilian Kindshofer
Apr 5 '16 at 9:47 6 How can I get my question to be not
flagged as opinion-based?
1 I use the filename='file', image='jpeg' arguments for the plot function, then have the script
Create a free Team 12 Split [revoke] tag into [sql-revoke] and
open the html file and copy the downloaded jpeg from my downloads folder to the directory of the html file.
What is Teams? Frankly it's a horrific method, but it does work... – JohnCH Dec 3 '17 at 15:19 [token-revoke]?

@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

Try this HTML / CSS / WebDesign


3 hours ago - TylerH

12 import plotly.offline
import plotly.graph_objs as go

plotly.offline.plot({"data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],


"layout": go.Layout(title="hello world")}, Linked
image='jpeg', image_filename='test')
11 How to save Plotly Offline graph in format
png?
and open it in Chrome
0 Javascript Plotly. How to create a plot but
not actually plot it.
Share Edit Follow edited Dec 26 '17 at 17:16 answered Mar 12 '17 at 8:21
0 Offline (no internet) conversion of local
Hendy LordK .html file (with JavaScript) to .png file from
8,559 15 52 66 131 1 4 Java without rendering it to screen

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

928 Peak detection in a 2D array


I found the solution in the documentation here:
1499 Generate random integers between 0 and 9

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?

py.image.save_as({'data':data}, 'scatter_plot', format='png') Plz Halp, Need Investors ASAP

Were leading edge ailerons tested?

Share Edit Follow answered Jan 27 '16 at 11:47 Are all stainless pans necessarily non stick?

Benares How can a butterfly dodge the windshield of a fast


896 1 6 12 moving car?

Ground state energy of the closure of an


I saw this, too, but it isn't saving the image from the Notebook, but rather from their server. – essentially self-adjoint operator
Matt Cremeens Jan 28 '16 at 14:36 If I pull a metal bar for long enough with a constant
small force, will it eventually break?
Well, apparently you do need a connection to the server, but the graph does not appear afterwards in your
plotly account, so it is not public. Could it be ok for you? – Benares Jan 28 '16 at 17:35 Photo Competition 2021-05-03: Typography

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 R᠎e᠎d᠎u᠎n᠎d᠎ancy

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?

Why is “disabled“ preferred over “handicapped”?


Add a comment
Wolstenholme numbers

Why does "ls" take extremely long in a small


Simple way of using python plotly graphs offline: directory that used to be big? How to fix this?

Restricted-source, take this!


2 1) Write import statements
A planet without the materials to make jet engines
-- plausible?
import plotly.graph_objs as go
import plotly as plotly What fueled the street lights in 13th-century
Cordoba?
import plotly.express as px
Euler equation in Continuous time VS Discrete
time
2) write your plotly graph code e.g. Is Feudal Elective better than Confederate
Partition?

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)

3) name your figure (provide reader-friendly name :) )

plotly.offline.plot(fig, filename= output_filename + ".html")

4) Well-done! Please add comments, if you like my answer!

Share Edit Follow answered Nov 14 '19 at 2:06


Shantanu Deshmukh
261 3 10

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

Here says to use

-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)

# Save the figure as a png image:


py.image.save_as(fig, 'my_plot.png')

Share Edit Follow answered Jul 10 '16 at 10:42


RFQED
35 4

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

Post Your Answer

Not the answer you're looking for? Browse other questions tagged python html image python-2.7

plotly or ask your own question.

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

You might also like