From 4255f8a3012775c15d835e466b1a4b3323a5c421 Mon Sep 17 00:00:00 2001 From: davidkyle210 <46031439+davidkyle210@users.noreply.github.com> Date: Fri, 12 Mar 2021 14:39:06 -0800 Subject: [PATCH 1/2] Enable multiple plots per cell in iframe renderer --- .../python/plotly/plotly/io/_base_renderers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index f5aec7e61cd..f99625bab6f 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -545,6 +545,8 @@ def __init__( self.animation_opts = animation_opts self.include_plotlyjs = include_plotlyjs self.html_directory = html_directory + self.last_focus_cell = None + self.last_focus_cell_output_ct = 1 def to_mimebundle(self, fig_dict): from plotly.io import write_html @@ -608,8 +610,17 @@ def to_mimebundle(self, fig_dict): def build_filename(self): ip = IPython.get_ipython() if IPython else None cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 if ip else 0 - filename = "{dirname}/figure_{cell_number}.html".format( - dirname=self.html_directory, cell_number=cell_number + if self.last_focus_cell == cell_number: + output_ct_suffix = f"_{self.last_focus_cell_output_ct}" + self.last_focus_cell_output_ct += 1 + else: + self.last_focus_cell = cell_number + self.last_focus_cell_output_ct = 1 + output_ct_suffix = "" + filename = "{dirname}/figure_{cell_number}{output_ct_suffix}.html".format( + dirname=self.html_directory, + cell_number=cell_number, + output_ct_suffix=output_ct_suffix, ) return filename From bde51362cea79fec5457a71c14bf362c05d555d8 Mon Sep 17 00:00:00 2001 From: davidkyle210 <46031439+davidkyle210@users.noreply.github.com> Date: Mon, 15 Mar 2021 13:53:37 -0700 Subject: [PATCH 2/2] add explanation of multiplot iframe in doc string --- packages/python/plotly/plotly/io/_base_renderers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index f99625bab6f..26a0fbefde2 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -524,7 +524,10 @@ class IFrameRenderer(MimetypeRenderer): Note that the HTML files in `iframe_figures/` are numbered according to the IPython cell execution count and so they will start being overwritten each time the kernel is restarted. This directory may be deleted whenever - the kernel is restarted and it will be automatically recreated. + the kernel is restarted and it will be automatically recreated. If a cell + contains multiple plots, a second index is appended to the file name. For + example, figure_8_2.html would be the third figure in the eighth cell + executed. mime type: 'text/html' """