我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用pyqtgraph.ColorMap()。
def colormap_lut(color = 'viridis', ncolors = None): # build lookup table if color == 'r': pos = np.array([0.0, 1.0]) color = np.array([[0,0,0,255], [255,0,0,255]], dtype=np.ubyte) ncolors = 512; elif color =='g': pos = np.array([0.0, 1.0]) color = np.array([[0,0,0,255], [0,255,0,255]], dtype=np.ubyte) ncolors = 512; elif color =='b': pos = np.array([0.0, 1.0]) color = np.array([[0,0,0,255], [0,0,255,255]], dtype=np.ubyte) ncolors = 512; else: #pos = np.array([0.0, 0.25, 0.5, 0.75, 1.0]) #color = np.array([[0,0,255,255], [0,255,255,255], [0,255,0,255], [255,255,0,255], [255,0,0,255]], dtype=np.ubyte) #color = np.array([[0,0,128,255], [0,255,255,255], [0,255,0,255], [255,255,0,255], [128,0,0,255]], dtype=np.ubyte) cmap = cm.get_cmap(color); if ncolors is None: ncolors = cmap.N; pos = np.linspace(0.0, 1.0, ncolors); color = cmap(pos, bytes = True); cmap = pg.ColorMap(pos, color) return cmap.getLookupTable(0.0, 1.0, ncolors);
def getpgcmap(cmp='BuRd'): import pyqtgraph as pg import numpy as np if cmp =='bryw': STEPS = np.array([0.0, 0.2, 0.6, 1.0]) CLRS = ['k', 'r', 'y', 'w'] ## Create a ColorMap clrmp = pg.ColorMap(STEPS, np.array([pg.colorTuple(pg.Color(c)) for c in CLRS])) ## Get the LookupTable lut = clrmp.getLookupTable() elif cmp == 'TrmBlk': pos = np.array([0.0, 0.5, 1.0]) color = np.array([[0,0,0,255], [255,128,0,255], [255,255,0,255]], dtype=np.ubyte) map = pg.ColorMap(pos, color) lut = map.getLookupTable(0.0, 1.0, 256) elif cmp == 'RdBu': pos = np.array([0.0,0.5,1.0]) color = np.array([[255,0,0,0],[255,255,255,255],[0,0,255,0]],dtype=np.ubyte) map = pg.ColorMap(pos,color) lut = map.getLookupTable(0.0,1.0,256) elif cmp == 'BuRd': pos = np.array([0.0,0.5,1.0]) color = np.array([[0,0,255,0],[255,255,255,255],[255,0,0,0]],dtype=np.ubyte) map = pg.ColorMap(pos,color) lut = map.getLookupTable(0.0,1.0,256) return lut
def __init__(self): color_positions = np.linspace(0.0, 1.0, num=len(self.COLORS)) self.colormap = pg.ColorMap(color_positions, self.COLORS.astype(int)) self.cmap_normed = pg.ColorMap(color_positions, self.COLORS_INV / 255) # get the LookUpTable (LUT), first two params should match the position # scale extremes passed to ColorMap(). # Return an RGB(A) lookup table (ndarray). Insert starting and stopping # value and the number of points in the returned lookup table: self.lut = self.colormap.getLookupTable(0, 1, 2000)
def create_colormap(cnt): """ create a colormap containing cnt values :param cnt: :return: """ col_map = pg.ColorMap(np.array([0, .5, 1]), np.array([[0, 0, 1., 1.], [0, 1., 0, 1.], [1., 0, 0, 1.]])) indexes = np.linspace(0, 1, cnt) return col_map.map(indexes, mode="qcolor")
def __init__(self, model): from pyqtgraph.graphicsItems.GradientEditorItem import Gradients self._component = 'weight' KitePlot.__init__(self, model) self.model = model gradient = Gradients['thermal'] self.cmap = pg.ColorMap( pos=[c[0] for c in gradient['ticks']], color=[c[1] for c in gradient['ticks']], mode=gradient['mode']) self.image.setLookupTable(self.cmap.getLookupTable()) self.setLabels( bottom={'Leaf #', ''}, left={'Leaf #', ''}) self.setAspectLocked(True) self.setMouseEnabled(x=False, y=False) self.hint = { 'leaf1': 0, 'leaf2': 0, 'weight': num.nan} self.hint_text.template =\ '<span style="font-family: monospace; color: #fff;'\ 'background-color: #000;">'\ 'Leaf #1: {leaf1:d} | Leaf #2: {leaf2:d} | '\ 'Weight {weight:e}</span>' self.update()