importnumpyasnpimportpyqtgraphaspgclassIndexedAxis(pg.AxisItem):""" Axis where pixels are mapped using a numpy array """def__init__(self,orientation,mapping=None,**kw):super(IndexedAxis,self).__init__(orientation,**kw)self.mapping=mappingself.fmt="{:.02f}"deftickStrings(self,values,scale,spacing):ifself.mappingisNone:returnsuper(IndexedAxis,self).tickStrings(values,scale,spacing)# count values smaller than 0labels=[]idx=np.array(values,dtype=np.int)-1left_pad=np.count_nonzero(idx<0)right_pad=np.count_nonzero(idx>=self.mapping.size)idx=np.compress(np.logical_and(idx>=0,idx<self.mapping.size),idx)labels.extend([""]*left_pad)labels.extend([self.fmt.format(v)forvinself.mapping[idx]])labels.extend([""]*right_pad)returnlabels
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.