@@ -509,6 +509,9 @@ class Stream:
509
509
"""
510
510
Interface to Plotly's real-time graphing API.
511
511
512
+ NOTE: Streaming is no longer supported in Plotly Cloud.
513
+ Streaming is still available as part of Plotly On-Premises.
514
+
512
515
Initialize a Stream object with a stream_id
513
516
found in {plotly_domain}/settings.
514
517
Real-time graphs are initialized with a call to `plot` that embeds
@@ -624,74 +627,49 @@ def write(self, trace, layout=None,
624
627
you can 'write' to it in real time.
625
628
626
629
positional arguments:
627
- trace - A valid plotly trace object (e.g., Scatter, Heatmap, etc.).
628
- Not all keys in these are `stremable` run help(Obj) on the type
629
- of trace your trying to stream, for each valid key, if the key
630
- is streamable, it will say 'streamable = True'. Trace objects
631
- must be dictionary-like.
630
+ trace - A dict of properties to stream
631
+ Some valid keys for trace dictionaries:
632
+ 'x', 'y', 'text', 'z', 'marker', 'line'
632
633
633
634
keyword arguments:
634
- layout (default=None) - A valid Layout object
635
+ layout (default=None) - A valid Layout object or dict with
636
+ compatible properties
635
637
Run help(plotly.graph_objs.Layout)
636
638
637
- Some valid keys for trace dictionaries:
638
- 'x', 'y', 'text', 'z', 'marker', 'line'
639
-
640
639
Examples:
641
- >>> write(dict(x=1, y=2)) # assumes 'scatter' type
642
- >>> write(Bar(x=[1, 2, 3], y=[10, 20, 30]))
643
- >>> write(Scatter(x=1, y=2, text='scatter text'))
644
- >>> write(Scatter(x=1, y=3, marker=Marker(color='blue')))
645
- >>> write(Heatmap(z=[[1, 2, 3], [4, 5, 6]]))
640
+
641
+ Append a point to a scatter trace
642
+ >>> write(dict(x=1, y=2))
643
+
644
+ Overwrite the x and y properties of a scatter trace
645
+ >>> write(dict(x=[1, 2, 3], y=[10, 20, 30]))
646
+
647
+ Append a point to a scatter trace and set the points text value
648
+ >>> write(dict(x=1, y=2, text='scatter text'))
649
+
650
+ Append a point to a scatter trace and set the points color
651
+ >>> write(dict(x=1, y=3, marker=go.Marker(color='blue')))
652
+
653
+ Set a new z value array for a Heatmap trace
654
+ >>> write(dict(z=[[1, 2, 3], [4, 5, 6]]))
646
655
647
656
The connection to plotly's servers is checked before writing
648
657
and reconnected if disconnected and if the response status code
649
658
is in `reconnect_on`.
650
659
651
660
For more help, see: `help(plotly.plotly.Stream)`
652
661
or see examples and tutorials here:
653
- http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
654
662
655
663
"""
656
- # always bypass validation in here as
657
- # now automatically done
658
- validate = False
659
664
660
665
# Convert trace objects to dictionaries
661
666
if isinstance (trace , BaseTraceType ):
662
- trace = trace .to_plotly_json ()
663
-
664
- stream_object = dict ()
665
- stream_object .update (trace )
666
- if 'type' not in stream_object :
667
- # tests if Scatter contains invalid kwargs
668
- dummy_obj = copy .deepcopy (Scatter (** stream_object ))
669
- stream_object = Scatter (** stream_object )
670
- stream_object ['type' ] = 'scatter'
671
-
672
- # TODO: remove this validation as now it's
673
- # done automatically
674
- if validate :
675
- try :
676
- tools .validate (stream_object , stream_object ['type' ])
677
- except exceptions .PlotlyError as err :
678
- raise exceptions .PlotlyError (
679
- "Part of the data object with type, '{0}', is invalid. "
680
- "This will default to 'scatter' if you do not supply a "
681
- "'type'. If you do not want to validate your data objects "
682
- "when streaming, you can set 'validate=False' in the call "
683
- "to 'your_stream.write()'. Here's why the object is "
684
- "invalid:\n \n {1}" .format (stream_object ['type' ], err )
685
- )
686
- if layout is not None :
687
- try :
688
- tools .validate (layout , 'Layout' )
689
- except exceptions .PlotlyError as err :
690
- raise exceptions .PlotlyError (
691
- "Your layout kwarg was invalid. "
692
- "Here's why:\n \n {0}" .format (err )
693
- )
694
- del stream_object ['type' ]
667
+ stream_object = trace .to_plotly_json ()
668
+ else :
669
+ stream_object = copy .deepcopy (trace )
670
+
671
+ # Remove 'type' if present since this trace type cannot be changed
672
+ stream_object .pop ('type' , None )
695
673
696
674
if layout is not None :
697
675
stream_object .update (dict (layout = layout ))
0 commit comments