Skip to content

Commit

Permalink
A few renderers default updates (#1571)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jonmmease authored May 25, 2019
1 parent 6a85e4b commit bccb4dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 4 additions & 11 deletions plotly/io/_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bccb4dc

Please sign in to comment.