@@ -669,3 +669,105 @@ def reorder_traces(self, current_indices, new_indices=None):
669
669
if new_indices is not None :
670
670
message ['newIndices' ] = new_indices
671
671
self ._handle_outgoing_message (message )
672
+
673
+ def extend_traces (self , update , indices , max_points = None ):
674
+ """ Append data points to existing traces in the Plotly graph.
675
+
676
+ Args:
677
+ update (dict):
678
+ dict where keys are the graph attribute strings
679
+ and values are arrays of arrays with values to extend.
680
+
681
+ Each array in the array will extend a trace.
682
+
683
+ Valid keys include:
684
+ 'x', 'y', 'text,
685
+ 'marker.color', 'marker.size', 'marker.symbol',
686
+ 'marker.line.color', 'marker.line.width'
687
+
688
+ indices (list, int):
689
+ Specify which traces to apply the `update` dict to.
690
+ If indices are not given, the update will apply to
691
+ the traces in order.
692
+
693
+ max_points (int or dict, optional):
694
+ If specified, then only show the `max_points` most
695
+ recent points in the graph.
696
+ This is useful to prevent traces from becoming too
697
+ large (and slow) or for creating "windowed" graphs
698
+ in monitoring applications.
699
+
700
+ To set max_points to different values for each trace
701
+ or attribute, set max_points to a dict mapping keys
702
+ to max_points values. See the examples below.
703
+
704
+ Examples:
705
+ Initialization - Start each example below with this setup:
706
+ ```
707
+ from plotly.widgets import Graph
708
+ from IPython.display import display
709
+
710
+ graph = GraphWidget()
711
+ graph.plot([
712
+ {'x': [], 'y': []},
713
+ {'x': [], 'y': []}
714
+ ])
715
+
716
+ display(graph)
717
+ ```
718
+
719
+ Example 1 - Extend the first trace with x and y data
720
+ ```
721
+ graph.extend_traces({'x': [[1,2,3]], 'y': [[10,20,30]]}, [0])
722
+ ```
723
+
724
+ Example 2 - Extend the second trace with x and y data
725
+ ```
726
+ graph.extend_traces({'x': [[1,2,3]], 'y': [[10,20,30]]}, [1])
727
+ ```
728
+
729
+ Example 3 - Extend the first two traces with x and y data
730
+ ```
731
+ graph.extend_traces({
732
+ 'x': [[1,2,3], [2,3,4]],
733
+ 'y': [[10,20,30], [3,4,3]]
734
+ }, [0, 1])
735
+ ```
736
+
737
+ Example 4 - Extend the first trace with x and y data and
738
+ limit the length of data in that trace to 50
739
+ points.
740
+ ```
741
+
742
+ graph.extend_traces({
743
+ 'x': [range(100)],
744
+ 'y': [range(100)]
745
+ }, [0, 1], max_points=50)
746
+ ```
747
+
748
+ Example 5 - Extend the first and second trace with x and y data
749
+ and limit the length of data in the first trace to
750
+ 25 points and the second trace to 50 points.
751
+ ```
752
+ new_points = range(100)
753
+ graph.extend_traces({
754
+ 'x': [new_points, new_points],
755
+ 'y': [new_points, new_points]
756
+ },
757
+ [0, 1],
758
+ max_points={
759
+ 'x': [25, 50],
760
+ 'y': [25, 50]
761
+ }
762
+ )
763
+ ```
764
+ """
765
+ message = {
766
+ 'task' : 'extendTraces' ,
767
+ 'update' : update ,
768
+ 'graphId' : self ._graphId ,
769
+ 'indices' : indices
770
+ }
771
+ if max_points is not None :
772
+ message ['maxPoints' ] = max_points
773
+ self ._handle_outgoing_message (message )
0 commit comments