@@ -406,21 +406,35 @@ def open(self):
406
406
{'Host' : streaming_url ,
407
407
'plotly-streamtoken' : self .stream_id })
408
408
409
- def write (self , data , layout = None , validate = True ,
409
+ def write (self , trace , layout = None , validate = True ,
410
410
reconnect_on = (200 , '' , 408 )):
411
- """ Write `data` to your stream. This will plot the
412
- `data` in your graph in real-time.
411
+ """Write to an open stream.
413
412
414
- `data` is a plotly formatted dict.
415
- Valid keys:
413
+ Once you've instantiated a 'Stream' object with a 'stream_id',
414
+ you can 'write' to it in real time.
415
+
416
+ positional arguments:
417
+ trace - A valid plotly trace object (e.g., Scatter, Heatmap, etc.).
418
+ Not all keys in these are `stremable` run help(Obj) on the type
419
+ of trace your trying to stream, for each valid key, if the key
420
+ is streamable, it will say 'streamable = True'. Trace objects
421
+ must be dictionary-like.
422
+
423
+ keyword arguments:
424
+ layout (default=None) - A valid Layout object
425
+ Run help(plotly.graph_objs.Layout)
426
+ validate (default = True) - Validate this stream before sending?
427
+ This will catch local errors if set to True.
428
+
429
+ Some valid keys for trace dictionaries:
416
430
'x', 'y', 'text', 'z', 'marker', 'line'
417
431
418
432
Examples:
419
- >>> write(dict(x = 1, y = 2))
420
- >>> write(dict(x = [1, 2, 3], y = [10, 20, 30]))
421
- >>> write(dict(x = 1, y = 2, text = 'scatter text'))
422
- >>> write(dict(x = 1, y = 3, marker = dict (color = 'blue')))
423
- >>> write(dict(z = [[1,2, 3], [4,5, 6]]))
433
+ >>> write(dict(x= 1, y= 2)) # assumes 'scatter' type
434
+ >>> write(Bar(x= [1, 2, 3], y= [10, 20, 30]))
435
+ >>> write(Scatter(x= 1, y= 2, text= 'scatter text'))
436
+ >>> write(Scatter(x= 1, y= 3, marker=Marker (color= 'blue')))
437
+ >>> write(Heatmap(z= [[1, 2, 3], [4, 5, 6]]))
424
438
425
439
The connection to plotly's servers is checked before writing
426
440
and reconnected if disconnected and if the response status code
@@ -431,7 +445,7 @@ def write(self, data, layout=None, validate=True,
431
445
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
432
446
"""
433
447
stream_object = dict ()
434
- stream_object .update (data )
448
+ stream_object .update (trace )
435
449
if 'type' not in stream_object :
436
450
stream_object ['type' ] = 'scatter'
437
451
if validate :
0 commit comments