Skip to content

Commit 906d3f2

Browse files
committed
Merge branch 'master' of https://github.com/plotly/python-api into tls.embed_with_URLs
merge document-stream branch
2 parents afc23b3 + 5857c07 commit 906d3f2

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ def __new__(mcs, name, bases, attrs):
237237
descr = str(obj_info[key]['description'])
238238
except KeyError:
239239
descr = undocumented
240-
str_1 = "{} [required={}] (value={}):\n".format(key, required,
241-
val_types)
240+
str_1 = "{} [required={}] (value={})".format(
241+
key, required, val_types)
242+
if "streamable" in obj_info[key] and obj_info[key]["streamable"]:
243+
str_1 += " (streamable)"
244+
str_1 += ":\n"
242245
str_1 = "\t" + "\n\t".join(textwrap.wrap(str_1,
243246
width=width1)) + "\n"
244247
str_2 = "\t\t" + "\n\t\t".join(textwrap.wrap(descr,

plotly/plotly/plotly.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,21 +406,35 @@ def open(self):
406406
{'Host': streaming_url,
407407
'plotly-streamtoken': self.stream_id})
408408

409-
def write(self, data, layout=None, validate=True,
409+
def write(self, trace, layout=None, validate=True,
410410
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.
413412
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:
416430
'x', 'y', 'text', 'z', 'marker', 'line'
417431
418432
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]]))
424438
425439
The connection to plotly's servers is checked before writing
426440
and reconnected if disconnected and if the response status code
@@ -431,7 +445,7 @@ def write(self, data, layout=None, validate=True,
431445
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
432446
"""
433447
stream_object = dict()
434-
stream_object.update(data)
448+
stream_object.update(trace)
435449
if 'type' not in stream_object:
436450
stream_object['type'] = 'scatter'
437451
if validate:

0 commit comments

Comments
 (0)