Skip to content

Commit 4ed0b85

Browse files
committed
allow empty Fig, {}, [] as a way to clear a graph (great idea @theengineear !)
1 parent fc22d6d commit 4ed0b85

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

plotly/widgets/graph_widget.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from IPython.display import Javascript, display
99

1010
from plotly import utils, tools
11+
from plotly.graph_objs import Figure
1112
from pkg_resources import resource_string
1213

1314
# Load JS widget code
@@ -249,10 +250,14 @@ def message_handler(widget, ranges):
249250
def plot(self, figure_or_data, validate=True):
250251
"""Plot figure_or_data in the Plotly graph.
251252
"""
252-
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)
253+
if figure_or_data == {} or figure_or_data == Figure():
254+
validate = False
255+
256+
figure = tools.return_figure_from_figure_or_data(figure_or_data,
257+
validate)
253258
message = {
254259
'task': 'newPlot',
255-
'data': figure['data'],
260+
'data': figure.get('data', []),
256261
'layout': figure.get('layout', {}),
257262
'graphId': self._graphId
258263
}

0 commit comments

Comments
 (0)