Fix: colormap: Support various arguments as color (#1014)

* colormap: Support various arguments as color

* Using mapping for speed and consistency (suggested by @j9ac9k)
This commit is contained in:
2xB 2019-08-18 05:38:05 +02:00 committed by Ogi Moore
parent b7b431de8d
commit ff30a82298

View File

@ -1,6 +1,7 @@
import numpy as np import numpy as np
from .Qt import QtGui, QtCore from .Qt import QtGui, QtCore
from .python2_3 import basestring from .python2_3 import basestring
from .functions import mkColor
class ColorMap(object): class ColorMap(object):
@ -56,9 +57,9 @@ class ColorMap(object):
=============== ============================================================== =============== ==============================================================
**Arguments:** **Arguments:**
pos Array of positions where each color is defined pos Array of positions where each color is defined
color Array of RGBA colors. color Array of colors.
Integer data types are interpreted as 0-255; float data types Values are interpreted via
are interpreted as 0.0-1.0 :func:`mkColor() <pyqtgraph.mkColor>`.
mode Array of color modes (ColorMap.RGB, HSV_POS, or HSV_NEG) mode Array of color modes (ColorMap.RGB, HSV_POS, or HSV_NEG)
indicating the color space that should be used when indicating the color space that should be used when
interpolating between stops. Note that the last mode value is interpolating between stops. Note that the last mode value is
@ -68,7 +69,11 @@ class ColorMap(object):
self.pos = np.array(pos) self.pos = np.array(pos)
order = np.argsort(self.pos) order = np.argsort(self.pos)
self.pos = self.pos[order] self.pos = self.pos[order]
self.color = np.array(color)[order] self.color = np.apply_along_axis(
func1d = lambda x: mkColor(x).getRgb(),
axis = -1,
arr = color,
)[order]
if mode is None: if mode is None:
mode = np.ones(len(pos)) mode = np.ones(len(pos))
self.mode = mode self.mode = mode
@ -225,7 +230,7 @@ class ColorMap(object):
x = np.linspace(start, stop, nPts) x = np.linspace(start, stop, nPts)
table = self.map(x, mode) table = self.map(x, mode)
if not alpha: if not alpha and mode != self.QCOLOR:
return table[:,:3] return table[:,:3]
else: else:
return table return table