Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d2b9880
added option to download an image of the most recent plot
yankev Jun 2, 2016
89c53db
remove an alert, change name of function
yankev Jun 2, 2016
c769ad6
updated docstring
yankev Jun 2, 2016
555d89a
removed unused variable `selected`
yankev Jun 2, 2016
6ff77d6
more docstring updates
yankev Jun 2, 2016
78fc1d7
added the ability to download plots when calling iplot
yankev Jun 3, 2016
341e87f
fixed the inline download method
yankev Jun 3, 2016
17485bc
renamed variables so tests will pass
yankev Jun 3, 2016
8eae6bd
attempt at stopping image download on future notebook openings
yankev Jun 4, 2016
ad728a3
fixed the download on refresh
yankev Jun 4, 2016
b2f9db9
fixing code to fix tests
yankev Jun 4, 2016
bdb4b85
Revert "fixing code to fix tests"
yankev Jun 4, 2016
0effa54
removed redundant return from _plot_html
yankev Jun 4, 2016
3172843
removed unused download arguments
yankev Jun 4, 2016
151f23e
providing functionality to all offline plot calls
yankev Jun 5, 2016
cae796e
pep8 and edit message in confirmation to download image
yankev Jun 5, 2016
8b39241
fixed typo
yankev Jun 5, 2016
e20da3e
ensuring the use of the correct argument names, and proper assignment…
yankev Jun 5, 2016
6abf3f9
added new arguments to docstrings
yankev Jun 5, 2016
cac15c5
changed `download_image` parameter to `image`
yankev Jun 7, 2016
a49d903
changed default value for image_filename
yankev Jun 7, 2016
f7d972c
added warning messages indicating the option to use `py.image`
yankev Jun 7, 2016
4256891
changed default filename for `download_notebook_image`
yankev Jun 7, 2016
d447ae4
add download image examples, update more default values
yankev Jun 7, 2016
bd46038
more docstring fixes and amending examples
yankev Jun 7, 2016
1c7d517
removed `download_notebook_image()` function
yankev Jun 7, 2016
f5baa3e
removed `download_notebook_image` from module init
yankev Jun 7, 2016
dbbad22
merged image and format into one parameter: image
yankev Jun 8, 2016
5bf4dd5
added new logic to deal with the new image parameter (iplot, plot)
yankev Jun 10, 2016
1892ab6
rename some arguments, typos, and formatting
yankev Jun 10, 2016
94a55f9
added confirm message to iplot mode
yankev Jun 10, 2016
6ea4e6d
edit value error
yankev Jun 10, 2016
e60a5dd
put download scripts into a function
yankev Jun 10, 2016
f44ad45
remove old scripts replaced by function calls
yankev Jun 10, 2016
e943120
remove image server warnings
yankev Jun 10, 2016
7b4681a
address PR comments
yankev Jun 14, 2016
0582283
fixed function names, as well as added a better check for the caller …
yankev Jun 14, 2016
8689112
Revert "fixed function names, as well as added a better check for the…
yankev Jun 14, 2016
cf90fba
renamed calls to `get_image_download_script` and fixed docstring
yankev Jun 14, 2016
4235cd4
fix ValueError message
yankev Jun 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
providing functionality to all offline plot calls
  • Loading branch information
yankev committed Jun 5, 2016
commit 151f23efa2bb40925d0e24338ec4ca519de03ed6
39 changes: 33 additions & 6 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ def plot(figure_or_data,
show_link=True, link_text='Export to plot.ly',
validate=True, output_type='file',
include_plotlyjs=True,
filename='temp-plot.html',
auto_open=True):
filename='temp-plot.html', auto_open=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't flake if you don't supply a filename twice, right? Will we end up with temp-plot.html (1) or something? Or, does the OS just handle it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nvm, looks like this was here before your changes. 👍

download_image=False, image_filename='plot', format='png',
_width = 800, _height=600):
""" Create a plotly graph locally as an HTML document or string.

Example:
Expand Down Expand Up @@ -347,13 +348,32 @@ def plot(figure_or_data,
else:
plotly_js_script = ''

# write the download script:
if download_image:
script = ('<script>'
'function downloadimage(format, height, width,'
' filename) {{'
'var p = document.getElementById(\'{plot_id}\');'
'Plotly.downloadImage(p, {{format: format, height: height, '
'width: width, filename: filename}});'
'}};'
'if(confirm(\'Do you want to save this image?\')) {{'
'downloadimage(\'{format}\', {height}, {width}, '
'\'{filename}\');}}'
'</script>'
).format(format=format, width=_width, height=_height,
filename=image_filename, plot_id=plotdivid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script the same as above? Can we factor this out to be a little more DRY 🐫.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part it's the same. Although for the iplot version I added a check to see if the document was completely loaded. This was to ensure that images don't get downloaded again on page reloads. I could definitely put this into a function though, with two options.

else:
script = ''

f.write(''.join([
'<html>',
'<head><meta charset="utf-8" /></head>',
'<body>',
plotly_js_script,
plot_html,
resize_script,
script,
'</body>',
'</html>']))

Expand All @@ -380,7 +400,9 @@ def plot(figure_or_data,
def plot_mpl(mpl_fig, resize=False, strip_style=False,
verbose=False, show_link=True, link_text='Export to plot.ly',
validate=True, output_type='file', include_plotlyjs=True,
filename='temp-plot.html', auto_open=True):
filename='temp-plot.html', auto_open=True,
download_image=False, image_filename='plot', format='png',
_height=600, _width=800):
"""
Convert a matplotlib figure to a Plotly graph stored locally as HTML.

Expand Down Expand Up @@ -442,12 +464,15 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False,
"""
plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose)
return plot(plotly_plot, show_link, link_text, validate, output_type,
include_plotlyjs, filename, auto_open)
include_plotlyjs, filename, auto_open, download_image,
image_filename, format, _height, _width)


def iplot_mpl(mpl_fig, resize=False, strip_style=False,
verbose=False, show_link=True,
link_text='Export to plot.ly', validate=True):
link_text='Export to plot.ly', validate=True,
donwload_image=False, image_filename='plot', format='png',
_height=600, _width=800):
"""
Convert a matplotlib figure to a plotly graph and plot inside an IPython
notebook without connecting to an external server.
Expand Down Expand Up @@ -492,7 +517,9 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False,
```
"""
plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose)
return iplot(plotly_plot, show_link, link_text, validate)
return iplot(plotly_plot, show_link, link_text, validate,
download_image=download_image, image_filename=image_filename,
format=format, _height=_height, _width=_width)


def enable_mpl_offline(resize=False, strip_style=False,
Expand Down