From bccb4dc12843b249d65845760dcd8c88facc6a2c Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 25 May 2019 06:29:35 -0400 Subject: [PATCH] A few renderers default updates (#1571) * 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. * Set _to_activate list rather than extend so that it doesn't keep growing * 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 | 15 ++++----------- plotly/offline/offline.py | 4 ++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/plotly/io/_renderers.py b/plotly/io/_renderers.py index 293f75e9bb..821ae0c308 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): @@ -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 diff --git a/plotly/offline/offline.py b/plotly/offline/offline.py index 2e30dd91b3..6cb8cefde1 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