'Write to an open stream.
Once you\'ve instantiated a \'Stream\' object with a \'stream_id\',
you can \'write\' to it in real time.
positional arguments:
trace - A valid plotly trace object (e.g., Scatter, Heatmap, etc.).
Not all keys in these are `stremable` run help(Obj) on the type
of trace your trying to stream, for each valid key, if the key
is streamable, it will say \'streamable = True\'. Trace objects
must be dictionary-like.
keyword arguments:
layout (default=None) - A valid Layout object
Run help(plotly.graph_objs.Layout)
validate (default = True) - Validate this stream before sending?
This will catch local errors if set to
True.
Some valid keys for trace dictionaries:
\'x\', \'y\', \'text\', \'z\', \'marker\', \'line\'
Examples:
>>> write(dict(x=1, y=2))  # assumes \'scatter\' type
>>> write(Bar(x=[1, 2, 3], y=[10, 20, 30]))
>>> write(Scatter(x=1, y=2, text=\'scatter text\'))
>>> write(Scatter(x=1, y=3, marker=Marker(color=\'blue\')))
>>> write(Heatmap(z=[[1, 2, 3], [4, 5, 6]]))
The connection to plotly\'s servers is checked before writing
and reconnected if disconnected and if the response status code
is in `reconnect_on`.
For more help, see: `help(plotly.plotly.Stream)`
or see examples and tutorials here:
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb'

def write(self, trace, layout=None, validate=True, reconnect_on=(200, '', 408)):

    stream_object = dict()
    stream_object.update(trace)
    if ('type' not in stream_object):
        stream_object['type'] = 'scatter'
    if validate:
        try:
            tools.validate(stream_object, stream_object['type'])
        except exceptions.PlotlyError as err:
            raise exceptions.PlotlyError("Part    of    the    data    object    with    type,    '{0}',    is    invalid.    This    will    default    to    'scatter'    if    you    do    not    supply    a    'type'.    If    you    do    not    want    to    validate    your    data    objects    when    streaming,    you    can    set    'validate=False'    in    the    call    to    'your_stream.write()'.    Here's    why    the    object    is    invalid:\n\n{1}".format(stream_object['type'], err))
        if (layout is not None):
            try:
                tools.validate(layout, 'Layout')
            except exceptions.PlotlyError as err:
                raise exceptions.PlotlyError("Your    layout    kwarg    was    invalid.    Here's    why:\n\n{0}".format(err))
    del stream_object['type']
    if (layout is not None):
        stream_object.update(dict(layout=layout))
    jdata = _json.dumps(stream_object, cls=utils.PlotlyJSONEncoder)
    jdata += '\n'
    try:
        self._stream.write(jdata, reconnect_on=reconnect_on)
    except AttributeError:
        raise exceptions.PlotlyError('Stream    has    not    been    opened    yet,    cannot    write    to    a    closed    connection.    Call    `open()`    on    the    stream    to    open    the    stream.')
