|
6 | 6 | import os
|
7 | 7 |
|
8 | 8 | import six
|
9 |
| -from plotly.io import to_json, to_image |
| 9 | +from plotly.io import to_json, to_image, write_image |
10 | 10 | from plotly import utils, optional_imports
|
11 | 11 | from plotly.io._orca import ensure_server
|
12 | 12 | from plotly.offline.offline import _get_jconfig, get_plotlyjs
|
| 13 | +from plotly.offline import plot |
| 14 | +from plotly.tools import return_figure_from_figure_or_data |
13 | 15 |
|
14 | 16 | ipython_display = optional_imports.get_module('IPython.display')
|
15 | 17 | IPython = optional_imports.get_module('IPython')
|
@@ -631,3 +633,21 @@ def render(self, fig_dict):
|
631 | 633 | default_height='100%',
|
632 | 634 | )
|
633 | 635 | open_html_in_browser(html, self.using, self.new, self.autoraise)
|
| 636 | + |
| 637 | + |
| 638 | +class SphinxGalleryRenderer(ExternalRenderer): |
| 639 | + |
| 640 | + def render(self, fig_dict): |
| 641 | + stack = inspect.stack() |
| 642 | + # Name of script from which plot function was called is retrieved |
| 643 | + try: |
| 644 | + filename = stack[3].filename # let's hope this is robust... |
| 645 | + except: #python 2 |
| 646 | + filename = stack[3][1] |
| 647 | + filename_root, _ = os.path.splitext(filename) |
| 648 | + filename_html = filename_root + '.html' |
| 649 | + filename_png = filename_root + '.png' |
| 650 | + figure = return_figure_from_figure_or_data(fig_dict, True) |
| 651 | + _ = plot(fig_dict, auto_open=False, |
| 652 | + filename=filename_html) |
| 653 | + write_image(figure, filename_png) |
0 commit comments