@@ -24,8 +24,8 @@ class SliderGraph(PlotWidget):
2424 Plot background color
2525 """
2626
27- def __init__ (self , x_axis_label , y_axis_label , callback , background = "w" ):
28- super ().__init__ (background = background )
27+ def __init__ (self , x_axis_label , y_axis_label , callback ):
28+ super ().__init__ (background = "w" )
2929
3030 axis = self .getAxis ("bottom" )
3131 axis .setLabel (x_axis_label )
@@ -49,34 +49,51 @@ def __init__(self, x_axis_label, y_axis_label, callback, background="w"):
4949 self .selection_limit = None
5050 self .data_increasing = None # true if data mainly increasing
5151
52- def update (self , x , y , colors , cutpoint_x = None , selection_limit = None ):
52+ def update (self , x , y , colors , cutpoint_x = None , selection_limit = None ,
53+ names = None ):
5354 """
5455 Function replots a graph.
5556
5657 Parameters
5758 ----------
5859 x : np.ndarray
5960 One-dimensional array with X coordinates of the points
60- y : list
61+ y : array-like
6162 List of np.ndarrays that contains an array of Y values for each
6263 sequence.
63- colors : list
64+ colors : array-like
6465 List of Qt colors (eg. Qt.red) for each sequence.
6566 cutpoint_x : int, optional
6667 A starting cutpoint - the location of the vertical line.
6768 selection_limit : tuple
6869 The tuple of two values that limit the range for selection.
70+ names : array-like
71+ The name of each sequence that shows in the legend, if None
72+ legend is not shown.
73+ legend_anchor : array-like
74+ The anchor of the legend in the graph
6975 """
7076 self .clear_plot ()
77+ if names is None :
78+ names = [None ] * len (y )
79+
7180 self .sequences = y
7281 self .x = x
7382 self .selection_limit = selection_limit
7483
7584 self .data_increasing = [np .sum (d [1 :] - d [:- 1 ]) > 0 for d in y ]
7685
7786 # plot sequence
78- for s , c in zip (y , colors ):
79- self .plot (x , s , pen = mkPen (QColor (c ), width = 2 ), antialias = True )
87+ for s , c , n , inc in zip (y , colors , names , self .data_increasing ):
88+ c = QColor (c )
89+ self .plot (x , s , pen = mkPen (c , width = 2 ), antialias = True )
90+
91+ if n is not None :
92+ label = TextItem (
93+ text = n , anchor = (0 , 1 ), color = QColor (0 , 0 , 0 , 128 ))
94+ label .setPos (x [- 1 ], s [- 1 ])
95+ self ._set_anchor (label , len (x ) - 1 , inc )
96+ self .addItem (label )
8097
8198 self ._plot_cutpoint (cutpoint_x )
8299 self .setRange (xRange = (x .min (), x .max ()),
0 commit comments