77
88from IPython .display import display
99
10+ """
11+ Requires
12+ pip install PyQtWebEngine
13+ pip install ipywidgets
14+ """
15+
1016def plot ():
1117 # fig = go.Figure(data=[go.Scattergl(x=[1, 2, 3], y=[4, 5, 6])])
1218 x = [1 , 2 , 3 ]
@@ -20,7 +26,7 @@ def plot():
2026
2127out = Output ()
2228
23- class Backend (QtCore .QObject ):
29+ class myBackend (QtCore .QObject ):
2430 pointChanged = QtCore .Signal (float , float )
2531
2632 # @QtCore.Signal(float,float)
@@ -34,7 +40,7 @@ def __init__(self, parent=None):
3440
3541 # self.button = QtWidgets.QPushButton('Plot', self)
3642 # self.browser = QtWebEngineWidgets.QWebEngineView(self)
37- self .browser = QtWebEngineWidgets .QWebEngineView ()
43+ self .browser : QtWebEngineWidgets . QWebEngineView = QtWebEngineWidgets .QWebEngineView ()
3844
3945 # self.vlayout = QtWidgets.QVBoxLayout(self)
4046 # self.vlayout.addWidget(self.button, alignment=QtCore.Qt.AlignHCenter)
@@ -55,20 +61,23 @@ def onPointChanged(self, x, y):
5561 def plot2 (self ):
5662 # map_view = QtWebEngineWidgets.QWebEngineView()
5763
58- backend = Backend (self )
64+ backend = myBackend (self )
5965 backend .pointChanged .connect (self .onPointChanged )
66+
6067 channel = QtWebChannel .QWebChannel (self )
6168 channel .registerObject ('backend' , backend )
69+
6270 self .browser .page ().setWebChannel (channel )
6371
6472 # file = QtCore.QDir.current().absoluteFilePath("index.html")
6573 # map_view.load(QtCore.QUrl.fromLocalFile(file))
6674
6775 x = [1 , 2 , 3 ]
6876 y = [4 , 5 , 6 ]
69- self .fig = go .FigureWidget ([go .Scatter (x = x , y = y , mode = 'markers' )])
77+ self .fig : go . FigureWidget = go .FigureWidget ([go .Scatter (x = x , y = y , mode = 'markers' )])
7078
71- scatter = self .fig .data [0 ]
79+ # The data property is a tuple of the figure's trace objects
80+ scatter = self .fig .data [0 ] # FigureWidget
7281 scatter .on_click (self .update_point )
7382
7483 self .browser .setHtml (self .fig .to_html (include_plotlyjs = 'cdn' ))
@@ -81,6 +90,7 @@ def plot2(self):
8190
8291 @out .capture (clear_output = True )
8392 def update_point (self , trace , points , selector ):
93+ sys .exit (1 )
8494 print ('!!!!' )
8595
8696 def show_graph (self ):
0 commit comments