From a779924676f5bd4b10c6f5b1acc59c8720ae5fa3 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 21 May 2019 06:32:33 -0400 Subject: [PATCH 1/3] Init notebook* renderers at the end when set with `init_notebook_mode` This seems to resolve the issue where the figure is autosized to a smaller height in JupyterLab. --- 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 2e30dd91b3f..6cb8cefde1b 100644 --- a/plotly/offline/offline.py +++ b/plotly/offline/offline.py @@ -272,9 +272,9 @@ def init_notebook_mode(connected=False): raise ImportError('`iplot` can only run inside an IPython Notebook.') if connected: - pio.renderers.default = 'notebook_connected+plotly_mimetype' + pio.renderers.default = 'plotly_mimetype+notebook_connected' else: - pio.renderers.default = 'notebook+plotly_mimetype' + pio.renderers.default = 'plotly_mimetype+notebook' # Trigger immediate activation of notebook. This way the plotly.js # library reference is available to the notebook immediately From b7be9f87aeb9fd420c98c52c8544d5b9dc324e44 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 21 May 2019 06:33:19 -0400 Subject: [PATCH 2/3] Set _to_activate list rather than extend so that it doens't keep growing --- plotly/io/_renderers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plotly/io/_renderers.py b/plotly/io/_renderers.py index 293f75e9bbf..d2695b61663 100644 --- a/plotly/io/_renderers.py +++ b/plotly/io/_renderers.py @@ -133,7 +133,7 @@ def default(self, value): self._default_renderers = [self[name] for name in renderer_names] # Register renderers for activation before their next use - self._to_activate.extend(self._default_renderers) + self._to_activate = list(self._default_renderers) @property def render_on_display(self): From 14fccf660fba196da2cd12b5c50e4f6594e99d2b Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 21 May 2019 06:38:01 -0400 Subject: [PATCH 3/3] Use notebook rather than notebook_connected in default v4 renderer This will bloat the notebook by couple of MB, but things will work offline by default. --- plotly/io/_renderers.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/plotly/io/_renderers.py b/plotly/io/_renderers.py index d2695b61663..821ae0c3085 100644 --- a/plotly/io/_renderers.py +++ b/plotly/io/_renderers.py @@ -420,17 +420,10 @@ def show(fig, renderer=None, validate=True, **kwargs): default_renderer = 'vscode' # Fallback to renderer combination that will work automatically - # in the classic notebook, jupyterlab, nteract, vscode, and - # nbconvert HTML export. We use 'notebook_connected' rather than - # 'notebook' to avoid bloating notebook size and slowing down - # plotly.py initial import. This comes at the cost of requiring - # internet connectivity to view, but that is a preferable - # trade-off to adding ~3MB to each saved notebook. - # - # Note that this doesn't cause any problem for offline - # JupyterLab users. + # in the classic notebook (offline), jupyterlab, nteract, vscode, and + # nbconvert HTML export. if not default_renderer: - default_renderer = 'notebook_connected+plotly_mimetype' + default_renderer = 'plotly_mimetype+notebook' else: # If ipython isn't available, try to display figures in the default # browser