@@ -91,6 +91,25 @@ class LinePlotStyle:
9191 MEAN_DARK_FACTOR = 110
9292
9393
94+ class LinePlotAxisItem (pg .AxisItem ):
95+ def __init__ (self , * args , ** kwargs ):
96+ super ().__init__ (* args , ** kwargs )
97+ self ._ticks = None
98+
99+ def set_ticks (self , ticks ):
100+ self ._ticks = dict (enumerate (ticks , 1 )) if ticks else None
101+
102+ def tickStrings (self , values , scale , spacing ):
103+ if not self ._ticks :
104+ return []
105+ strings = []
106+ for v in values :
107+ v = v * scale
108+ if float (v ).is_integer ():
109+ strings .append (self ._ticks .get (int (v ), "" ))
110+ return strings
111+
112+
94113class LinePlotViewBox (ViewBox ):
95114 selection_changed = Signal (np .ndarray )
96115
@@ -172,8 +191,10 @@ def reset(self):
172191
173192class LinePlotGraph (pg .PlotWidget ):
174193 def __init__ (self , parent ):
194+ self .bottom_axis = LinePlotAxisItem (orientation = "bottom" )
175195 super ().__init__ (parent , viewBox = LinePlotViewBox (),
176- background = "w" , enableMenu = False )
196+ background = "w" , enableMenu = False ,
197+ axisItems = {"bottom" : self .bottom_axis })
177198 self .view_box = self .getViewBox ()
178199 self .selection = set ()
179200 self .legend = self ._create_legend (((1 , 0 ), (1 , 0 )))
@@ -213,7 +234,7 @@ def reset(self):
213234 self .selection = set ()
214235 self .view_box .reset ()
215236 self .clear ()
216- self .getAxis ('bottom' ).setTicks (None )
237+ self .getAxis ('bottom' ).set_ticks (None )
217238 self .legend .hide ()
218239
219240 def select_button_clicked (self ):
@@ -593,8 +614,8 @@ def setup_plot(self):
593614 if self .data is None :
594615 return
595616
596- ticks = [[( i , a .name ) for i , a in enumerate ( self .graph_variables , 1 )] ]
597- self .graph .getAxis (' bottom' ). setTicks (ticks )
617+ ticks = [a .name for a in self .graph_variables ]
618+ self .graph .getAxis (" bottom" ). set_ticks (ticks )
598619 self .plot_groups ()
599620 self .apply_selection ()
600621 self .graph .view_box .enableAutoRange ()
0 commit comments