Skip to content

Commit bccb4dc

Browse files
authored
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.
1 parent 6a85e4b commit bccb4dc

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

plotly/io/_renderers.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def default(self, value):
133133
self._default_renderers = [self[name] for name in renderer_names]
134134

135135
# Register renderers for activation before their next use
136-
self._to_activate.extend(self._default_renderers)
136+
self._to_activate = list(self._default_renderers)
137137

138138
@property
139139
def render_on_display(self):
@@ -420,17 +420,10 @@ def show(fig, renderer=None, validate=True, **kwargs):
420420
default_renderer = 'vscode'
421421

422422
# Fallback to renderer combination that will work automatically
423-
# in the classic notebook, jupyterlab, nteract, vscode, and
424-
# nbconvert HTML export. We use 'notebook_connected' rather than
425-
# 'notebook' to avoid bloating notebook size and slowing down
426-
# plotly.py initial import. This comes at the cost of requiring
427-
# internet connectivity to view, but that is a preferable
428-
# trade-off to adding ~3MB to each saved notebook.
429-
#
430-
# Note that this doesn't cause any problem for offline
431-
# JupyterLab users.
423+
# in the classic notebook (offline), jupyterlab, nteract, vscode, and
424+
# nbconvert HTML export.
432425
if not default_renderer:
433-
default_renderer = 'notebook_connected+plotly_mimetype'
426+
default_renderer = 'plotly_mimetype+notebook'
434427
else:
435428
# If ipython isn't available, try to display figures in the default
436429
# browser

plotly/offline/offline.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ def init_notebook_mode(connected=False):
272272
raise ImportError('`iplot` can only run inside an IPython Notebook.')
273273

274274
if connected:
275-
pio.renderers.default = 'notebook_connected+plotly_mimetype'
275+
pio.renderers.default = 'plotly_mimetype+notebook_connected'
276276
else:
277-
pio.renderers.default = 'notebook+plotly_mimetype'
277+
pio.renderers.default = 'plotly_mimetype+notebook'
278278

279279
# Trigger immediate activation of notebook. This way the plotly.js
280280
# library reference is available to the notebook immediately

0 commit comments

Comments
 (0)