Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5677c8

Browse files
committed
add plot command to widgets
1 parent 2eef301 commit c5677c8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

plotly/widgets/graph_widget.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from collections import deque
22
import json
3-
import os
43
import uuid
54

65
# TODO: protected imports?
76
from IPython.html import widgets
87
from IPython.utils.traitlets import Unicode
98
from IPython.display import Javascript, display
109

11-
from plotly import utils
10+
from plotly import utils, tools
1211
from pkg_resources import resource_string
1312

1413
# Load JS widget code
@@ -247,6 +246,18 @@ def message_handler(widget, ranges):
247246
"""
248247
self._handle_registration('zoom', callback, remove)
249248

249+
def plot(self, figure_or_data, validate=True):
250+
"""Plot figure_or_data in the Plotly graph.
251+
"""
252+
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
253+
message = {
254+
'task': 'newPlot',
255+
'data': figure['data'],
256+
'layout': figure.get('layout', {}),
257+
'graphId': self._graphId
258+
}
259+
self._handle_outgoing_message(message)
260+
250261
def restyle(self, data, indices=None):
251262
"""Update the style of existing traces in the Plotly graph.
252263

0 commit comments

Comments
 (0)