Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have plot and iplot return instance of FigureWidget #1071

Closed
timkpaine opened this issue Jul 25, 2018 · 9 comments
Closed

Have plot and iplot return instance of FigureWidget #1071

timkpaine opened this issue Jul 25, 2018 · 9 comments

Comments

@timkpaine
Copy link

Its a bit strange for the different interfaces between Notebook/JLab, is it possible to unify the two?

@jonmmease
Copy link
Contributor

Hi @timkpaine , Thanks for the idea. Here are a couple of thoughts

  1. There isn't actually a difference between the interfaces supported for the classic notebook and JupyterLab. In both situations you can use the online/offline plot/iplot methods and you can use the new FigureWidget class.

Installation is just a little different:

  • For classic notebook the init_notebook_mode method must be called in order to use offline iplot, and the notebook extension to support FigureWidget is bundled with the plotly Python package.
  • For JupyterLab the init_notebook_mode method isn't needed. But to use offline iplot you need to install the @jupyterlab/plotly-extension JupyterLab extension. And to use FigureWidget you need to install the plotlywidget JupyterLab extension. (This is all in the README)
  1. I agree that it would simpler if the offline iplot method could just return a FigureWidget instance that would display itself. But there are at least two reasons that we can't do this (yet?).
  • The ipywidgets framework isn't supported as widely as the mechanism behind iplot across the non-notebook Jupyter ecosystem. The main example I'm thinking of here is nteract, which supports iplot but not ipywidgets. Also, nbconvert (For exporting notebooks to other formats) doesn't support ipywidgets yet (But almost Update widgets CDN for ipywidgets 7 w/fallback jupyter/nbconvert#792), so the iplot mechanism is needed in this case as well.

  • FigureWidget doesn't (yet) cover the entire Plotly.js API. For instance, FigureWidget doesn't support animation frames yet (e.g. https://plot.ly/python/animations/). And it doesn't support transforms (e.g. https://plot.ly/python/group-by/). So the iplot path is needed as a sort of escape hatch to make sure there's a way to handle these kinds of situations.

@timkpaine
Copy link
Author

Hm, I'm getting different behavior when I return plotlywidget vs when I call iplot for the cufflinks port to 3.0. Let me double check

@jonmmease
Copy link
Contributor

Ok, just let us know

@timkpaine
Copy link
Author

@jonmmease here is a repro, iplot doesn't work but FigureWidget does:

import numpy as np
import plotly.graph_objs as go
import plotly.offline as py_offline

x = np.random.randn(1000)
y = np.random.randn(1000)

py_offline.init_notebook_mode()
py_offline.iplot(go.Figure([{'x': x, 'y': y, 'type': 'histogram2dcontour'}]))
go.FigureWidget(data=[{'x': x, 'y': y, 'type': 'histogram2dcontour'}])

@jonmmease
Copy link
Contributor

Hi @timkpaine , thanks for the example code.

This is what I see when I run it (plotly 3.1.1, notebook 5.6.0, plotlywidget 0.2.1):

screen shot 2018-08-21 at 6 24 53 pm

Could you explain what difference you're seeing on your end?

@timkpaine
Copy link
Author

From jupyterlab?

@timkpaine
Copy link
Author

I only see the second chart, and a host of js errors:

plotly 3.1.1, notebook 5.6.0, plotlywidget 0.2.2, jupyterlab 0.34.0

@jonmmease
Copy link
Contributor

Yes, it works for me in JupyterLab as well.

For JupyterLab you need to have the @jupyterlab/plotly-extension JupyterLab extension installed in order to use offline.iplot (and in JupyterLab the init_notebook_mode call isn't needed). Double check the versions of everything in the README

@timkpaine
Copy link
Author

ahhh, so you need both the plotly AND plotlywidget extensions. got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants