Data is transfered to JS side using ipywidgets binary protocol without JSON serialization
# plotly
from plotly.graph_objs import Figure, FigureWidget, Scattergl
# numpy
import numpy as np
# core
import datetime
import time
import plotly.offline as py
py.init_notebook_mode()
IOPub data rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_data_rate_limit`.
# Create a one-million points scattergl trace
N = 1000000
scatt = Scattergl(x = np.random.randn(N),
y = np.random.randn(N),
mode = 'markers',
marker={'opacity': 0.8, 'line': {'width': 1}})
# Creating and displaying takes ~4 seconds
fig = FigureWidget(data=[scatt])
f
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-5-6fd26cca68ff> in <module>() 1 # Creating and displaying takes ~4 seconds ----> 2 fig = FigureWidget(data=[scatt]) 3 f /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/graph_objs/_figurewidget.pyc in __init__(self, data, layout, frames) 287 respective traces in the data attribute 288 """ --> 289 super(FigureWidget, self).__init__(data, layout, frames) 290 291 def add_area( /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/basewidget.pyc in __init__(self, data, layout, frames) 126 super(BaseFigureWidget, self).__init__(data=data, 127 layout_plotly=layout, --> 128 frames=frames) 129 130 # Validate Frames /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/basedatatypes.pyc in __init__(self, data, layout_plotly, frames) 131 # The _data property is a list of dicts containing the properties 132 # explicitly set by the user for each trace. --> 133 self._data = [deepcopy(trace._props) for trace in data] 134 135 # ### Create data defaults ### /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/basedatatypes.pyc in __setattr__(self, prop, value) 272 if prop.startswith('_') or hasattr(self, prop): 273 # Let known properties and private properties through --> 274 super(BaseFigure, self).__setattr__(prop, value) 275 else: 276 # Raise error on unknown public properties /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traitlets/traitlets.pyc in __set__(self, obj, value) 583 raise TraitError('The "%s" trait is read-only.' % self.name) 584 else: --> 585 self.set(obj, value) 586 587 def _validate(self, obj, value): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traitlets/traitlets.pyc in set(self, obj, value) 572 # we explicitly compare silent to True just in case the equality 573 # comparison above returns something other than True/False --> 574 obj._notify_trait(self.name, old_value, new_value) 575 576 def __set__(self, obj, value): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/traitlets/traitlets.pyc in _notify_trait(self, name, old_value, new_value) 1137 new=new_value, 1138 owner=self, -> 1139 type='change', 1140 )) 1141 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in notify_change(self, change) 395 if name in self.keys and self._should_send_property(name, change['new']): 396 # Send new state to front-end --> 397 self.send_state(key=name) 398 LoggingConfigurable.notify_change(self, change) 399 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in send_state(self, key) 280 state, buffer_keys, buffers = self._split_state_buffers(state) 281 msg = {'method': 'update', 'state': state, 'buffers': buffer_keys} --> 282 self._send(msg, buffers=buffers) 283 284 def get_state(self, key=None, drop_defaults=False): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in _send(self, msg, buffers) 534 """Sends a message to the model in the front-end.""" 535 if self.comm is not None and self.comm.kernel is not None: --> 536 self.comm.send(data=msg, buffers=buffers) 537 538 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/comm/comm.pyc in send(self, data, metadata, buffers) 119 """Send a message to the frontend-side version of this comm""" 120 self._publish_msg('comm_msg', --> 121 data=data, metadata=metadata, buffers=buffers, 122 ) 123 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/comm/comm.pyc in _publish_msg(self, msg_type, data, metadata, buffers, **keys) 63 data = {} if data is None else data 64 metadata = {} if metadata is None else metadata ---> 65 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys)) 66 self.kernel.session.send(self.kernel.iopub_socket, msg_type, 67 content, /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 165 out = {} 166 for k,v in iteritems(obj): --> 167 out[unicode_type(k)] = json_clean(v) 168 return out 169 if isinstance(obj, datetime): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 165 out = {} 166 for k,v in iteritems(obj): --> 167 out[unicode_type(k)] = json_clean(v) 168 return out 169 if isinstance(obj, datetime): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 165 out = {} 166 for k,v in iteritems(obj): --> 167 out[unicode_type(k)] = json_clean(v) 168 return out 169 if isinstance(obj, datetime): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 151 152 if isinstance(obj, list): --> 153 return [json_clean(x) for x in obj] 154 155 if isinstance(obj, dict): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 165 out = {} 166 for k,v in iteritems(obj): --> 167 out[unicode_type(k)] = json_clean(v) 168 return out 169 if isinstance(obj, datetime): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 165 out = {} 166 for k,v in iteritems(obj): --> 167 out[unicode_type(k)] = json_clean(v) 168 return out 169 if isinstance(obj, datetime): /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipykernel/jsonutil.pyc in json_clean(obj) 171 172 # we don't understand it, it's probably an unserializable object --> 173 raise ValueError("Can't clean for JSON: %r" % obj) ValueError: Can't clean for JSON: <memory at 0x109b11050>
# Plotting using iplot takes ~25 seconds
fig = Figure(data=[scatt])
py.iplot(fig)
IOPub data rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_data_rate_limit`.