Repository: pyqtgraph/pyqtgraph

Issue:
ColorMap getLookupTable fails when alpha=None
<!-- In the following, please describe your issue in detail! -->
### Short description
The `getLookupTable` method of `pyqtgraph.ColorMap` fails to automatically determine whether alpha values should be included in a lookup table.

### Code to reproduce

```python
import pyqtgraph as pg

colors = [
    (0, 0, 0),
    (45, 5, 61),
    (84, 42, 55)
]
cmap = pg.ColorMap(pos=(0, 1, 2), color=colors)

cmap.getLookupTable(alpha=False)  # Works
cmap.getLookupTable(alpha=True)  # Works, but returned lookup table does not contain alpha values.
cmap.getLookupTable()  # Does not work
```

### Expected behavior
A lookup table is returned.

### Real behavior
The following exception is thrown:

```
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    cmap.getLookupTable()  # Does not work
  File "...\venv\lib\site-packages\pyqtgraph\colormap.py", line 223, in getLookupTable
    alpha = self.usesAlpha()
  File "...\venv\lib\site-packages\pyqtgraph\colormap.py", line 236, in usesAlpha
    return np.any(self.color[:,3] != max)
IndexError: index 3 is out of bounds for axis 1 with size 3
```

### Tested environment(s)

 * PyQtGraph version: 0.11.0.dev0+gad7453c
 * Qt Python binding: 0.11.0.dev0+gad7453c
 * Python version: 3.7.3
 * NumPy version: 0.11.0.dev0+gad7453c
 * Operating system: Windows 10
 * Installation method: pip



Discussion:
The issue here is that `pg.ColorMap` accepts RGBA values for `color`, but it gets RGB values.
This would not be a bug itself, if the example `ImageView.py` would not do the exact same thing:

> ImageView.py:
> ```python3
> colors = [
>     (0, 0, 0),
>     (45, 5, 61),
>     (84, 42, 55),
>     (150, 87, 60),
>     (208, 171, 141),
>     (255, 255, 255)
> ]
> cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
> ```

There are now two obvious reactions:
a) Change the example to use RGBA
b) Automatically transform RGB to RGBA values in `ColorMap.__init__`

I suggest to iterate over `color` and parse the entries with `pg.functions.mkColor`, which would make the API more consistent. What do others think of this?
@wailashi You are probably helped with the information that you should currently initialize `pg.ColorMap` with RGBA values?
I came across this when trying to get a lookup table from a HistogramLUTWidget which I am using to change the colours on a scatter plot.

I was trying to do `pg.HistogramLUTWidget.gradient.colorMap().getLookupTable(mode='qcolor')`. This fails with the same error as in my first post.

While looking into this I found `pg.HistogramLUTWidget.gradient.getLookupTable()` which has a different method signature and does not return QColors.

[
Here is a gis](https://gist.github.com/wailashi/6ea42db5ac78f6af7a8f10a7771a13bc)t with a modified HistogramLUT.py from the examples directory with the failing getLookupTable calls.

For my use case `pg.HistogramLUTWidget.gradient.colorMap().getLookupTable(mode='qcolor', alpha=True)` is sufficient as I am not interested in the alpha values.


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


Test patch: