From d2b988063dd07460b24d7e2ef979ecfefc2b5890 Mon Sep 17 00:00:00 2001 From: yankev Date: Thu, 2 Jun 2016 15:04:17 -0400 Subject: [PATCH 01/40] added option to download an image of the most recent plot --- plotly/offline/__init__.py | 3 ++- plotly/offline/offline.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/plotly/offline/__init__.py b/plotly/offline/__init__.py index f4a5fc2d2b6..2ef7dd92653 100644 --- a/plotly/offline/__init__.py +++ b/plotly/offline/__init__.py @@ -10,5 +10,6 @@ iplot, iplot_mpl, plot, - plot_mpl + plot_mpl, + downloadImage, ) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 7a6df8eed40..6ce32b8cf36 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -508,3 +508,39 @@ def enable_mpl_offline(resize=False, strip_style=False, formatter.for_type(matplotlib.figure.Figure, lambda fig: iplot_mpl(fig, resize, strip_style, verbose, show_link, link_text, validate)) + +def downloadImage(format='png', height=600, width=800, + filename='newplot'): + + script = ('' + ).format(format=format, height=height, width=width, + filename=filename) + + display(HTML(script)) From 89c53db23390bacd49a04a2727c48cd65bcfe885 Mon Sep 17 00:00:00 2001 From: yankev Date: Thu, 2 Jun 2016 15:21:11 -0400 Subject: [PATCH 02/40] remove an alert, change name of function --- plotly/offline/__init__.py | 2 +- plotly/offline/offline.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plotly/offline/__init__.py b/plotly/offline/__init__.py index 2ef7dd92653..6e78c0b51dd 100644 --- a/plotly/offline/__init__.py +++ b/plotly/offline/__init__.py @@ -11,5 +11,5 @@ iplot_mpl, plot, plot_mpl, - downloadImage, + download_notebook_image, ) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 6ce32b8cf36..b483053fd3e 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -509,11 +509,11 @@ def enable_mpl_offline(resize=False, strip_style=False, lambda fig: iplot_mpl(fig, resize, strip_style, verbose, show_link, link_text, validate)) -def downloadImage(format='png', height=600, width=800, +def download_notebook_image(format='png', height=600, width=800, filename='newplot'): script = ('' ).format(format=format, height=height, width=width, filename=filename) From c769ad654fe935107ceb5728366d1e395b0fb6b0 Mon Sep 17 00:00:00 2001 From: yankev Date: Thu, 2 Jun 2016 16:14:36 -0400 Subject: [PATCH 03/40] updated docstring --- plotly/offline/offline.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index b483053fd3e..dc2571faa01 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -511,7 +511,18 @@ def enable_mpl_offline(resize=False, strip_style=False, def download_notebook_image(format='png', height=600, width=800, filename='newplot'): + """ + Download an image of the most recent plot. This function should be + called in a cell following the output cell that includes the plot. + Keyword arguments: + format -- sets the image format for the saved file (default='png') + Accepts formats include: .jpeg, .png, .svg, .webp + height -- sets the height of the image in px (default=600) + width -- sets the width of the image in px (default=800) + filename -- the name of the saved file without format extension + (default='newplot') + """ script = ('' + ).format(format=format, width=width, height=height, + filename=filename, plot_id=plot_id) + + display(HTML(script)) def plot(figure_or_data, show_link=True, link_text='Export to plot.ly', From 341e87f68640762439da6b5dcf2d775b77a6a1c2 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 3 Jun 2016 15:19:51 -0400 Subject: [PATCH 07/40] fixed the inline download method --- plotly/offline/offline.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 30ce55d401d..efbc52846ba 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -232,7 +232,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if not tools._ipython_imported: raise ImportError('`iplot` can only run inside an IPython Notebook.') - plot_html, plotdivid, width, height, plot_id = _plot_html( + plot_html, plotdivid, _width, _height, plot_id = _plot_html( figure_or_data, show_link, link_text, validate, '100%', 525, global_requirejs=True, download=download_image) @@ -241,11 +241,12 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', # Use the plot id to download the image now: script = ('' - ).format(format=format, width=width, height=height, - filename=filename, plot_id=plot_id) + ).format(format=format, width=width, height=height, + filename=filename, plot_id=plot_id) display(HTML(script)) From 17485bcf98ba45568845646efa8a1dc29ee3affd Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 3 Jun 2016 15:55:02 -0400 Subject: [PATCH 08/40] renamed variables so tests will pass --- plotly/offline/offline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index efbc52846ba..74aa7082146 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -189,7 +189,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True, download_image=False, format='png', - width=800, height=600, filename='newplot'): + _width=800, _height=600, filename='newplot'): """ Draw plotly graphs inside an IPython notebook without connecting to an external server. @@ -232,7 +232,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if not tools._ipython_imported: raise ImportError('`iplot` can only run inside an IPython Notebook.') - plot_html, plotdivid, _width, _height, plot_id = _plot_html( + plot_html, plotdivid, width, height, plot_id = _plot_html( figure_or_data, show_link, link_text, validate, '100%', 525, global_requirejs=True, download=download_image) @@ -245,7 +245,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'setTimeout(function() {{Plotly.downloadImage(div_id, {{format: \'{format}\', ' 'height: {height}, width: {width}, filename: \'{filename}\'}});}}, 500);' '' - ).format(format=format, width=width, height=height, + ).format(format=format, width=_width, height=_height, filename=filename, plot_id=plot_id) display(HTML(script)) From 8eae6bd5ae46e9b3401b03c514cb2827de9d0a02 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 3 Jun 2016 21:47:29 -0400 Subject: [PATCH 09/40] attempt at stopping image download on future notebook openings --- plotly/offline/offline.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 74aa7082146..d332d56f970 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -240,10 +240,23 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', # Use the plot id to download the image now: - script = ('' ).format(format=format, width=_width, height=_height, filename=filename, plot_id=plot_id) From ad728a309546f7e6e420c0d30cb0666666efbcc3 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 11:04:05 -0400 Subject: [PATCH 10/40] fixed the download on refresh --- plotly/offline/offline.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index d332d56f970..9873b6056a0 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -238,31 +238,27 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', display(HTML(plot_html)) - # Use the plot id to download the image now: - - script = ('' ).format(format=format, width=_width, height=_height, filename=filename, plot_id=plot_id) - + # allow time for the plot to draw + import time + time.sleep(1) + #inject code to download an image of the plot display(HTML(script)) + def plot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True, output_type='file', From b2f9db984af17306ebc5d8e9deec39a952af9c13 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 13:43:14 -0400 Subject: [PATCH 11/40] fixing code to fix tests --- plotly/offline/offline.py | 63 +++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 9873b6056a0..ae463264ed5 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -184,7 +184,10 @@ def _plot_html(figure_or_data, show_link, link_text, validate, id=plotdivid, script=script, height=height, width=width) - return plotly_html_div, plotdivid, width, height, plotdivid + if download: + return plotly_html_div, plotdivid, width, height, plotdivid + else: + return plotly_html_div, plotdivid, width, height def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', @@ -232,31 +235,39 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if not tools._ipython_imported: raise ImportError('`iplot` can only run inside an IPython Notebook.') - plot_html, plotdivid, width, height, plot_id = _plot_html( - figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=True, download=download_image) - - display(HTML(plot_html)) - - # Write script to download image of the plot - script = ('' - ).format(format=format, width=_width, height=_height, - filename=filename, plot_id=plot_id) - # allow time for the plot to draw - import time - time.sleep(1) - #inject code to download an image of the plot - display(HTML(script)) + def inject(): + display(HTML(plot_html)) + + # Write script to download image of the plot + script = ('' + ).format(format=format, width=_width, height=_height, + filename=filename, plot_id=plot_id) + # allow time for the plot to draw + import time + time.sleep(1) + #inject code to download an image of the plot + display(HTML(script)) + + if download_image: + plot_html, plotdivid, width, height, plot_id = _plot_html( + figure_or_data, show_link, link_text, validate, + '100%', 525, global_requirejs=True, download=download_image) + inject() + else: + plot_html, plotdivid, width, height = _plot_html( + figure_or_data, show_link, link_text, validate, + '100%', 525, global_requirejs=True, download=download_image) + inject() def plot(figure_or_data, From bdb4b851c6a4520ad7839da13905d2269f22ec45 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 13:55:17 -0400 Subject: [PATCH 12/40] Revert "fixing code to fix tests" This reverts commit b2f9db984af17306ebc5d8e9deec39a952af9c13. --- plotly/offline/offline.py | 63 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index ae463264ed5..9873b6056a0 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -184,10 +184,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, id=plotdivid, script=script, height=height, width=width) - if download: - return plotly_html_div, plotdivid, width, height, plotdivid - else: - return plotly_html_div, plotdivid, width, height + return plotly_html_div, plotdivid, width, height, plotdivid def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', @@ -235,39 +232,31 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if not tools._ipython_imported: raise ImportError('`iplot` can only run inside an IPython Notebook.') - def inject(): - display(HTML(plot_html)) - - # Write script to download image of the plot - script = ('' - ).format(format=format, width=_width, height=_height, - filename=filename, plot_id=plot_id) - # allow time for the plot to draw - import time - time.sleep(1) - #inject code to download an image of the plot - display(HTML(script)) - - if download_image: - plot_html, plotdivid, width, height, plot_id = _plot_html( - figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=True, download=download_image) - inject() - else: - plot_html, plotdivid, width, height = _plot_html( - figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=True, download=download_image) - inject() + plot_html, plotdivid, width, height, plot_id = _plot_html( + figure_or_data, show_link, link_text, validate, + '100%', 525, global_requirejs=True, download=download_image) + + display(HTML(plot_html)) + + # Write script to download image of the plot + script = ('' + ).format(format=format, width=_width, height=_height, + filename=filename, plot_id=plot_id) + # allow time for the plot to draw + import time + time.sleep(1) + #inject code to download an image of the plot + display(HTML(script)) def plot(figure_or_data, From 0effa54e73cb9c6fb43fc2b1392fc5b651d5bfd5 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 14:12:50 -0400 Subject: [PATCH 13/40] removed redundant return from _plot_html --- plotly/offline/offline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 9873b6056a0..442042fbc95 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -184,7 +184,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, id=plotdivid, script=script, height=height, width=width) - return plotly_html_div, plotdivid, width, height, plotdivid + return plotly_html_div, plotdivid, width, height def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', @@ -232,7 +232,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if not tools._ipython_imported: raise ImportError('`iplot` can only run inside an IPython Notebook.') - plot_html, plotdivid, width, height, plot_id = _plot_html( + plot_html, plotdivid, width, height = _plot_html( figure_or_data, show_link, link_text, validate, '100%', 525, global_requirejs=True, download=download_image) @@ -251,7 +251,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', '}}' '' ).format(format=format, width=_width, height=_height, - filename=filename, plot_id=plot_id) + filename=filename, plot_id=plotdivid) # allow time for the plot to draw import time time.sleep(1) From 3172843f66722f094445a30fb2b35c8f3ef64a86 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 14:24:25 -0400 Subject: [PATCH 14/40] removed unused download arguments --- plotly/offline/offline.py | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 442042fbc95..0e5faafa351 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -115,8 +115,7 @@ def init_notebook_mode(connected=False): def _plot_html(figure_or_data, show_link, link_text, validate, - default_width, default_height, global_requirejs, - download=False): + default_width, default_height, global_requirejs): figure = tools.return_figure_from_figure_or_data(figure_or_data, validate) @@ -234,29 +233,30 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', plot_html, plotdivid, width, height = _plot_html( figure_or_data, show_link, link_text, validate, - '100%', 525, global_requirejs=True, download=download_image) + '100%', 525, global_requirejs=True) display(HTML(plot_html)) - # Write script to download image of the plot - script = ('' - ).format(format=format, width=_width, height=_height, - filename=filename, plot_id=plotdivid) - # allow time for the plot to draw - import time - time.sleep(1) - #inject code to download an image of the plot - display(HTML(script)) + if download_image: + # Write script to download image of the plot + script = ('' + ).format(format=format, width=_width, height=_height, + filename=filename, plot_id=plotdivid) + # allow time for the plot to draw + import time + time.sleep(1) + # inject code to download an image of the plot + display(HTML(script)) def plot(figure_or_data, From 151f23efa2bb40925d0e24338ec4ca519de03ed6 Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 22:18:31 -0400 Subject: [PATCH 15/40] providing functionality to all offline plot calls --- plotly/offline/offline.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 0e5faafa351..5863fdd9e48 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -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, + download_image=False, image_filename='plot', format='png', + _width = 800, _height=600): """ Create a plotly graph locally as an HTML document or string. Example: @@ -347,6 +348,24 @@ def plot(figure_or_data, else: plotly_js_script = '' + # write the download script: + if download_image: + script = ('' + ).format(format=format, width=_width, height=_height, + filename=image_filename, plot_id=plotdivid) + else: + script = '' + f.write(''.join([ '', '', @@ -354,6 +373,7 @@ def plot(figure_or_data, plotly_js_script, plot_html, resize_script, + script, '', ''])) @@ -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. @@ -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. @@ -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, From cae796e060f17c0134062cf61edb4df167be58bf Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 22:33:47 -0400 Subject: [PATCH 16/40] pep8 and edit message in confirmation to download image --- plotly/offline/offline.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 5863fdd9e48..f7cfc652fef 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -265,7 +265,7 @@ def plot(figure_or_data, include_plotlyjs=True, filename='temp-plot.html', auto_open=True, download_image=False, image_filename='plot', format='png', - _width = 800, _height=600): + _width=800, _height=600): """ Create a plotly graph locally as an HTML document or string. Example: @@ -354,10 +354,11 @@ def plot(figure_or_data, 'function downloadimage(format, height, width,' ' filename) {{' 'var p = document.getElementById(\'{plot_id}\');' - 'Plotly.downloadImage(p, {{format: format, height: height, ' - 'width: width, filename: filename}});' + 'Plotly.downloadImage(p, {{format: format, height: ' + 'height, width: width, filename: filename}});' '}};' - 'if(confirm(\'Do you want to save this image?\')) {{' + 'if(confirm(\'Do you want to save this image as ' + '{filename}.{format}?\')) {{' 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '' @@ -558,6 +559,7 @@ def enable_mpl_offline(resize=False, strip_style=False, lambda fig: iplot_mpl(fig, resize, strip_style, verbose, show_link, link_text, validate)) + def download_notebook_image(format='png', height=600, width=800, filename='newplot'): """ From 8b39241a510e65cfecb298bf8c6a838f11b9d26a Mon Sep 17 00:00:00 2001 From: yankev Date: Sat, 4 Jun 2016 23:39:20 -0400 Subject: [PATCH 17/40] fixed typo --- plotly/offline/offline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index f7cfc652fef..74d295b5211 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -472,7 +472,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, def iplot_mpl(mpl_fig, resize=False, strip_style=False, verbose=False, show_link=True, link_text='Export to plot.ly', validate=True, - donwload_image=False, image_filename='plot', format='png', + download_image=False, image_filename='plot', _format='png', _height=600, _width=800): """ Convert a matplotlib figure to a plotly graph and plot inside an IPython @@ -520,7 +520,7 @@ 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, download_image=download_image, image_filename=image_filename, - format=format, _height=_height, _width=_width) + format=_format, _height=_height, _width=_width) def enable_mpl_offline(resize=False, strip_style=False, From e20da3e871145e52086fd84719679b087ac3bb78 Mon Sep 17 00:00:00 2001 From: yankev Date: Sun, 5 Jun 2016 00:37:49 -0400 Subject: [PATCH 18/40] ensuring the use of the correct argument names, and proper assignment of values --- plotly/offline/offline.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 74d295b5211..23875704da0 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -465,8 +465,9 @@ 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, download_image, - image_filename, format, _height, _width) + include_plotlyjs, filename, auto_open, + download_image=download_image, image_filename=image_filename, + format=format, _height=_height, _width=_width) def iplot_mpl(mpl_fig, resize=False, strip_style=False, @@ -519,7 +520,7 @@ 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, - download_image=download_image, image_filename=image_filename, + download_image=download_image, filename=image_filename, format=_format, _height=_height, _width=_width) From 6abf3f9179080f21cf923f43c0dab4c02f3ebd0d Mon Sep 17 00:00:00 2001 From: yankev Date: Sun, 5 Jun 2016 01:19:53 -0400 Subject: [PATCH 19/40] added new arguments to docstrings --- plotly/offline/offline.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 23875704da0..59c1bb15f4d 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -188,7 +188,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True, download_image=False, format='png', - _width=800, _height=600, filename='newplot'): + _width=800, _height=600, filename='plot'): """ Draw plotly graphs inside an IPython notebook without connecting to an external server. @@ -211,6 +211,14 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', has become outdated with your version of graph_reference.json or if you need to include extra, unnecessary keys in your figure. + downloage_image (default=False) -- If True, the image of the current plot + will be downloaded. + format (default='png') -- Specifies the format of the image to be + downloaded if `downlowad_image` is True. + filename (default='plot') -- Sets the name of the file your image + will be saved to. The extension should not be included. + _height (default=600) -- Specifies the height of the image in `px`. + _width (default=800) -- Specifies the width of the image in `px`. Example: ``` @@ -311,6 +319,14 @@ def plot(figure_or_data, auto_open (default=True) -- If True, open the saved file in a web browser after saving. This argument only applies if `output_type` is 'file'. + downloage_image (default=False) -- If True, the image of the current plot + will be downloaded. + format (default='png') -- Specifies the format of the image to be + downloaded if `downlowad_image` is True. + image_filename (default='plot') -- Sets the name of the file your image + will be saved to. The extension should not be included. + _height (default=600) -- Specifies the height of the image in `px`. + _width (default=800) -- Specifies the width of the image in `px`. """ if output_type not in ['div', 'file']: raise ValueError( @@ -447,6 +463,14 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, auto_open (default=True) -- If True, open the saved file in a web browser after saving. This argument only applies if `output_type` is 'file'. + downloage_image (default=False) -- If True, the image of the current plot + will be downloaded. + format (default='png') -- Specifies the format of the image to be + downloaded if `downlowad_image` is True. + image_filename (default='plot') -- Sets the name of the file your image + will be saved to. The extension should not be included. + _height (default=600) -- Specifies the height of the image in `px`. + _width (default=800) -- Specifies the width of the image in `px`. Example: ``` @@ -503,6 +527,14 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, has become outdated with your version of graph_reference.json or if you need to include extra, unnecessary keys in your figure. + downloage_image (default=False) -- If True, the image of the current plot + will be downloaded. + _format (default='png') -- Specifies the format of the image to be + downloaded if `downlowad_image` is True. + image_filename (default='plot') -- Sets the name of the file your image + will be saved to. The extension should not be included. + _height (default=600) -- Specifies the height of the image in `px`. + _width (default=800) -- Specifies the width of the image in `px`. Example: ``` From cac15c5aac9e7fe99e08cd65c11a9e67d1f4ffa7 Mon Sep 17 00:00:00 2001 From: yankev Date: Tue, 7 Jun 2016 12:26:19 -0400 Subject: [PATCH 20/40] changed `download_image` parameter to `image` --- plotly/offline/offline.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 59c1bb15f4d..b6acbc2cd26 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -187,7 +187,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', - validate=True, download_image=False, format='png', + validate=True, image=False, format='png', _width=800, _height=600, filename='plot'): """ Draw plotly graphs inside an IPython notebook without @@ -245,7 +245,7 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', display(HTML(plot_html)) - if download_image: + if image: # Write script to download image of the plot script = ('' - ).format(format=format, height=height, width=width, - filename=filename) - - display(HTML(script)) From f5baa3e6060e9f36676c93797063ea3eb9a4ce91 Mon Sep 17 00:00:00 2001 From: yankev Date: Tue, 7 Jun 2016 18:26:01 -0400 Subject: [PATCH 27/40] removed `download_notebook_image` from module init --- plotly/offline/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plotly/offline/__init__.py b/plotly/offline/__init__.py index 6e78c0b51dd..f4a5fc2d2b6 100644 --- a/plotly/offline/__init__.py +++ b/plotly/offline/__init__.py @@ -10,6 +10,5 @@ iplot, iplot_mpl, plot, - plot_mpl, - download_notebook_image, + plot_mpl ) From dbbad22445a794442b3dd2aea3017d92cbdf802f Mon Sep 17 00:00:00 2001 From: yankev Date: Wed, 8 Jun 2016 16:03:14 -0400 Subject: [PATCH 28/40] merged image and format into one parameter: image --- plotly/offline/offline.py | 92 +++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index ef4911fe880..177cd896174 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -185,10 +185,9 @@ def _plot_html(figure_or_data, show_link, link_text, validate, return plotly_html_div, plotdivid, width, height - def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', - validate=True, image=False, format='png', - _width=800, _height=600, filename='plot'): + validate=True, image=None, filename='plot_image', image_width=800, + image_height=600): """ Draw plotly graphs inside an IPython notebook without connecting to an external server. @@ -211,22 +210,23 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', has become outdated with your version of graph_reference.json or if you need to include extra, unnecessary keys in your figure. - image (default=False) -- If True, the image of the current plot - will be downloaded. - format (default='png') -- Specifies the format of the image to be - downloaded if `downlowad_image` is True. + image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets + the format of the image to be downloaded, if we choose to download an + image. This parameter has a default value of None indicating that no + image should be downloaded. filename (default='plot') -- Sets the name of the file your image will be saved to. The extension should not be included. - _height (default=600) -- Specifies the height of the image in `px`. - _width (default=800) -- Specifies the width of the image in `px`. + image_height (default=600) -- Specifies the height of the image in `px`. + image_width (default=800) -- Specifies the width of the image in `px`. Example: ``` from plotly.offline import init_notebook_mode, iplot init_notebook_mode() iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}]) - # We can also download an image of the plot by setting `image=True` - iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}], image=True) + # We can also download an image of the plot by setting the image to the + format you want ie: `image='png'` + iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}], image='png') ``` """ if not __PLOTLY_OFFLINE_INITIALIZED: @@ -264,11 +264,12 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '' - ).format(format=format, width=_width, height=_height, - filename=filename, plot_id=plotdivid) + ).format(format=format, width=image_width, + height=image_height, filename=filename, + plot_id=plotdivid) # allow time for the plot to draw import time - time.sleep(1) + time.sleep(0.1) # inject code to download an image of the plot display(HTML(script)) @@ -278,8 +279,8 @@ def plot(figure_or_data, validate=True, output_type='file', include_plotlyjs=True, filename='temp-plot.html', auto_open=True, - image=False, image_filename='plot_image', format='png', - _width=800, _height=600): + image=None, image_filename='plot_image', + image_width=800, image_height=600): """ Create a plotly graph locally as an HTML document or string. Example: @@ -288,9 +289,10 @@ def plot(figure_or_data, import plotly.graph_objs as go plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], filename='my-graph.html') - # We can also download an image of the plot by setting `image=True` + # We can also download an image of the plot by setting the image parameter + # to the image format we want plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], filename='my-graph.html' - image=True) + image='jpeg') ``` More examples below. @@ -328,14 +330,14 @@ def plot(figure_or_data, auto_open (default=True) -- If True, open the saved file in a web browser after saving. This argument only applies if `output_type` is 'file'. - image (default=False) -- If True, the image of the current plot - will be downloaded. - format (default='png') -- Specifies the format of the image to be - downloaded if `downlowad_image` is True. + image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets + the format of the image to be downloaded, if we choose to download an + image. This parameter has a default value of None indicating that no + image should be downloaded. image_filename (default='plot_image') -- Sets the name of the file your image will be saved to. The extension should not be included. - _height (default=600) -- Specifies the height of the image in `px`. - _width (default=800) -- Specifies the width of the image in `px`. + image_height (default=600) -- Specifies the height of the image in `px`. + image_width (default=800) -- Specifies the width of the image in `px`. """ if output_type not in ['div', 'file']: raise ValueError( @@ -392,7 +394,8 @@ def plot(figure_or_data, 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '' - ).format(format=format, width=_width, height=_height, + ).format(format=format, width=image_width, + height=image_height, filename=image_filename, plot_id=plotdivid) else: script = '' @@ -432,8 +435,8 @@ 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, - image=False, image_filename='plot_image', format='png', - _height=600, _width=800): + image=None, image_filename='plot_image', + image_height=600, image_width=800): """ Convert a matplotlib figure to a Plotly graph stored locally as HTML. @@ -477,14 +480,16 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, auto_open (default=True) -- If True, open the saved file in a web browser after saving. This argument only applies if `output_type` is 'file'. - image (default=False) -- If True, the image of the current plot - will be downloaded. + image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets + the format of the image to be downloaded, if we choose to download an + image. This parameter has a default value of None indicating that no + image should be downloaded. format (default='png') -- Specifies the format of the image to be downloaded if `downlowad_image` is True. image_filename (default='plot_image') -- Sets the name of the file your image will be saved to. The extension should not be included. - _height (default=600) -- Specifies the height of the image in `px`. - _width (default=800) -- Specifies the width of the image in `px`. + image_height (default=600) -- Specifies the height of the image in `px`. + image_width (default=800) -- Specifies the width of the image in `px`. Example: ``` @@ -500,21 +505,22 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, plot_mpl(fig) # If you want to to download an image of the figure as well - plot_mpl(fig, image=True) + plot_mpl(fig, image='png') ``` """ 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, image=image, image_filename=image_filename, - format=format, _height=_height, _width=_width) + format=format, image_height=image_height, + image_width=image_width) def iplot_mpl(mpl_fig, resize=False, strip_style=False, verbose=False, show_link=True, link_text='Export to plot.ly', validate=True, - image=False, image_filename='plot_image', _format='png', - _height=600, _width=800): + image=None, image_filename='plot_image', + image_height=600, image_width=800): """ Convert a matplotlib figure to a plotly graph and plot inside an IPython notebook without connecting to an external server. @@ -543,14 +549,14 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, has become outdated with your version of graph_reference.json or if you need to include extra, unnecessary keys in your figure. - image (default=False) -- If True, the image of the current plot will be - downloaded. - _format (default='png') -- Specifies the format of the image to be - downloaded if `downlowad_image` is True. + image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets + the format of the image to be downloaded, if we choose to download an + image. This parameter has a default value of None indicating that no + image should be downloaded. image_filename (default='plot_image') -- Sets the name of the file your image will be saved to. The extension should not be included. - _height (default=600) -- Specifies the height of the image in `px`. - _width (default=800) -- Specifies the width of the image in `px`. + image_height (default=600) -- Specifies the height of the image in `px`. + image_width (default=800) -- Specifies the width of the image in `px`. Example: ``` @@ -565,13 +571,13 @@ def iplot_mpl(mpl_fig, resize=False, strip_style=False, init_notebook_mode() iplot_mpl(fig) # and if you want to download an image of the figure as well - iplot_mpl(fig, image=True) + iplot_mpl(fig, image='jpeg') ``` """ plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose) return iplot(plotly_plot, show_link, link_text, validate, image=image, filename=image_filename, - format=_format, _height=_height, _width=_width) + image_height=image_height, image_width=image_width) def enable_mpl_offline(resize=False, strip_style=False, From 5bf4dd51c978f945366f5b7e5677b9b30597f15c Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 12:46:29 -0400 Subject: [PATCH 29/40] added new logic to deal with the new image parameter (iplot, plot) --- plotly/offline/offline.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 177cd896174..04fd4847e45 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -31,6 +31,8 @@ __PLOTLY_OFFLINE_INITIALIZED = False +__IMAGE_FORMATS = ['jpeg', 'svg', 'webp', 'svg'] + def download_plotlyjs(download_url): warnings.warn(''' @@ -248,6 +250,10 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', display(HTML(plot_html)) if image: + if image not in __IMAGE_FORMATS: + raise ValueError('The image parameter takes only the following' + 'format types: `png`, `jpeg`, `webp`, `svg`') + # if the check passes then download script injection will commence. warnings.warn('For higher resolution images and more export ' 'options, consider making requests to the ' 'Plotly image servers. Type help(\'py.image\') ' @@ -376,6 +382,11 @@ def plot(figure_or_data, plotly_js_script = '' if image: + if image not in __IMAGE_FORMATS: + raise ValueError('The image parameter takes only the + 'following format types: `png`, `jpeg`, ' + '`webp`, `svg`') + # if the check passes then download script is injected. warnings.warn('For higher resolution images and more export ' 'options, consider making requests to the ' 'Plotly image servers. Type help(\'py.image\') ' @@ -484,10 +495,8 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, the format of the image to be downloaded, if we choose to download an image. This parameter has a default value of None indicating that no image should be downloaded. - format (default='png') -- Specifies the format of the image to be - downloaded if `downlowad_image` is True. image_filename (default='plot_image') -- Sets the name of the file your - image will be saved to. The extension should not be included. + image will be saved to. The extension should not be included. image_height (default=600) -- Specifies the height of the image in `px`. image_width (default=800) -- Specifies the width of the image in `px`. From 1892ab62b528344429c67b47cdde8e53792a6668 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 14:19:14 -0400 Subject: [PATCH 30/40] rename some arguments, typos, and formatting --- plotly/offline/offline.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 04fd4847e45..83676d1d316 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -31,7 +31,7 @@ __PLOTLY_OFFLINE_INITIALIZED = False -__IMAGE_FORMATS = ['jpeg', 'svg', 'webp', 'svg'] +__IMAGE_FORMATS = ['jpeg', 'png', 'webp', 'svg'] def download_plotlyjs(download_url): @@ -251,8 +251,10 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if image: if image not in __IMAGE_FORMATS: - raise ValueError('The image parameter takes only the following' - 'format types: `png`, `jpeg`, `webp`, `svg`') + raise ValueError(''.join(['The image parameter takes only the' + 'following format types: `png`, `jpeg`, `webp`,' + ' `svg`'] + )) # if the check passes then download script injection will commence. warnings.warn('For higher resolution images and more export ' 'options, consider making requests to the ' @@ -270,12 +272,12 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '' - ).format(format=format, width=image_width, + ).format(format=image, width=image_width, height=image_height, filename=filename, plot_id=plotdivid) # allow time for the plot to draw import time - time.sleep(0.1) + time.sleep(1) # inject code to download an image of the plot display(HTML(script)) @@ -383,7 +385,7 @@ def plot(figure_or_data, if image: if image not in __IMAGE_FORMATS: - raise ValueError('The image parameter takes only the + raise ValueError('The image parameter takes only the ' 'following format types: `png`, `jpeg`, ' '`webp`, `svg`') # if the check passes then download script is injected. @@ -405,7 +407,7 @@ def plot(figure_or_data, 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '' - ).format(format=format, width=image_width, + ).format(format=image, width=image_width, height=image_height, filename=image_filename, plot_id=plotdivid) else: @@ -521,8 +523,7 @@ def plot_mpl(mpl_fig, resize=False, strip_style=False, return plot(plotly_plot, show_link, link_text, validate, output_type, include_plotlyjs, filename, auto_open, image=image, image_filename=image_filename, - format=format, image_height=image_height, - image_width=image_width) + image_height=image_height, image_width=image_width) def iplot_mpl(mpl_fig, resize=False, strip_style=False, From 94a55f9991ffb7c680693e1c55fa661f90b822bc Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 15:15:28 -0400 Subject: [PATCH 31/40] added confirm message to iplot mode --- plotly/offline/offline.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 83676d1d316..beb51e08cad 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -269,8 +269,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'width: width, filename: filename}});' '}};' 'if(document.readyState == \'complete\') {{' + 'if(confirm(\'Do you want to save this image as ' + '{filename}.{format}?\')) {{' 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' + '}}' '' ).format(format=image, width=image_width, height=image_height, filename=filename, From 6ea4e6d56f4acca2b1d2472c7d13966961621776 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 15:25:51 -0400 Subject: [PATCH 32/40] edit value error --- plotly/offline/offline.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index beb51e08cad..f1d718f681c 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -251,10 +251,9 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', if image: if image not in __IMAGE_FORMATS: - raise ValueError(''.join(['The image parameter takes only the' - 'following format types: `png`, `jpeg`, `webp`,' - ' `svg`'] - )) + raise ValueError('The image parameter takes only the ' + 'following format types: `png`, `jpeg`, ' + '`webp`, `svg`') # if the check passes then download script injection will commence. warnings.warn('For higher resolution images and more export ' 'options, consider making requests to the ' @@ -269,8 +268,8 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'width: width, filename: filename}});' '}};' 'if(document.readyState == \'complete\') {{' - 'if(confirm(\'Do you want to save this image as ' - '{filename}.{format}?\')) {{' + 'if(confirm(\'Do you want to save this image as ' + '{filename}.{format}?\')) {{' 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '}}' From e60a5dd7a4512506c13d4aa3c1924f3658562277 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 16:13:46 -0400 Subject: [PATCH 33/40] put download scripts into a function --- plotly/offline/offline.py | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index f1d718f681c..c7da8aba89c 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -48,6 +48,37 @@ def get_plotlyjs(): plotlyjs = resource_string('plotly', path).decode('utf-8') return plotlyjs +def image_download_script(type): + + if type == 'iplot': + check_start = 'if(document.readyState == \'complete\') {{' + check_end = '}}' + elif type == 'plot': + check_start = '' + check_end = '' + + return( + ('' + ) + ) + def init_notebook_mode(connected=False): """ @@ -269,7 +300,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', '}};' 'if(document.readyState == \'complete\') {{' 'if(confirm(\'Do you want to save this image as ' - '{filename}.{format}?\')) {{' + '{filename}.{format}?\\n\\n\\n\\n' + 'For higher resolution images and more export options, ' + 'consider making requests to our image servers. Type: ' + 'help(py.image) for more details.' + '\')) {{' 'downloadimage(\'{format}\', {height}, {width}, ' '\'{filename}\');}}' '}}' @@ -277,6 +312,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', ).format(format=image, width=image_width, height=image_height, filename=filename, plot_id=plotdivid) + script = image_download_script('iplot').format(format=image, + width=image_width, + height=image_height, + filename=filename, + plot_id=plotdivid) # allow time for the plot to draw import time time.sleep(1) @@ -412,6 +452,13 @@ def plot(figure_or_data, ).format(format=image, width=image_width, height=image_height, filename=image_filename, plot_id=plotdivid) + + script = image_download_script('plot') + script = script.format(format=image, + width=image_width, + height=image_height, + filename=image_filename, + plot_id=plotdivid) else: script = '' From f44ad4566c2744e97b3799bd298bd642da177538 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 16:15:29 -0400 Subject: [PATCH 34/40] remove old scripts replaced by function calls --- plotly/offline/offline.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index c7da8aba89c..b8cbedae575 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -291,27 +291,6 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'Plotly image servers. Type help(\'py.image\') ' 'for more details.', UserWarning) # Write script to download image of the plot - script = ('' - ).format(format=image, width=image_width, - height=image_height, filename=filename, - plot_id=plotdivid) script = image_download_script('iplot').format(format=image, width=image_width, height=image_height, @@ -437,22 +416,6 @@ def plot(figure_or_data, 'for more details.', UserWarning) # write the download script: - script = ('' - ).format(format=image, width=image_width, - height=image_height, - filename=image_filename, plot_id=plotdivid) - script = image_download_script('plot') script = script.format(format=image, width=image_width, From e943120d6838d4f3c9fbd3e2341472b1d31315b5 Mon Sep 17 00:00:00 2001 From: yankev Date: Fri, 10 Jun 2016 16:16:40 -0400 Subject: [PATCH 35/40] remove image server warnings --- plotly/offline/offline.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index b8cbedae575..9e897db113a 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -286,10 +286,6 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', 'following format types: `png`, `jpeg`, ' '`webp`, `svg`') # if the check passes then download script injection will commence. - warnings.warn('For higher resolution images and more export ' - 'options, consider making requests to the ' - 'Plotly image servers. Type help(\'py.image\') ' - 'for more details.', UserWarning) # Write script to download image of the plot script = image_download_script('iplot').format(format=image, width=image_width, @@ -410,11 +406,6 @@ def plot(figure_or_data, 'following format types: `png`, `jpeg`, ' '`webp`, `svg`') # if the check passes then download script is injected. - warnings.warn('For higher resolution images and more export ' - 'options, consider making requests to the ' - 'Plotly image servers. Type help(\'py.image\') ' - 'for more details.', UserWarning) - # write the download script: script = image_download_script('plot') script = script.format(format=image, From 7b4681a1c2f966b385da8f1683198932e51fddb3 Mon Sep 17 00:00:00 2001 From: yankev Date: Mon, 13 Jun 2016 22:05:57 -0400 Subject: [PATCH 36/40] address PR comments --- plotly/offline/offline.py | 41 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 9e897db113a..ba0c17cc188 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -10,6 +10,7 @@ import uuid import warnings from pkg_resources import resource_string +import time import webbrowser import plotly @@ -48,14 +49,26 @@ def get_plotlyjs(): plotlyjs = resource_string('plotly', path).decode('utf-8') return plotlyjs -def image_download_script(type): +def get_image_download_script(caller): + ''' + This function will return a script that will download an image of a Plotly + plot. - if type == 'iplot': + Keyword Arguments: + caller ('plot', 'iplot') -- specifies which function made the call for the + download script. If `iplot`, then an extra condition is added into the + download script to ensure that download prompts aren't iniitated on + page reloads. + ''' + + if caller == 'iplot': check_start = 'if(document.readyState == \'complete\') {{' check_end = '}}' - elif type == 'plot': + elif caller == 'plot': check_start = '' check_end = '' + else: + raise ValueError('caller should only be one of `iplot` or `plot`') return( ('