-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
In the doc string of makeARGB it says about the scale parameter that: By default this will be set to the length of the lookup table. However since commit e2f43ce this no longer the case. The scale is now set to the length of the lookup table - 1.
scale = lut.shape[0] - 1
I think this is wrong and the following code demonstrates that.
import numpy as np
import pyqtgraph as pg
lut1 = np.array([(0, 0, 0), (1, 1, 1), (2, 2, 2)])
vector = np.linspace(0.0, 1.0, 11)
data = np.expand_dims(vector, axis=0)
print("data: {}".format(data))
levels = np.amin(data), np.amax(data)
for scale in [None, 2, 3]:
res, _ = pg.makeARGB(data, lut1, levels=levels, scale=scale)
print("\nScale: {}".format(scale))
for idx, val in enumerate(vector):
color = res[0, idx, :]
print(" Value {:5.2f} -> RGBA {} ".format(val, color))
This applies a look up table with three colors to an array that ranges from 0.0 to 1.0 with steps of 0.1. It does this three times, first with the default scale parameter, then with scale = 2 and then with scale = 3.
Scale: None
Value 0.00 -> RGBA [ 0 0 0 255]
Value 0.10 -> RGBA [ 0 0 0 255]
Value 0.20 -> RGBA [ 0 0 0 255]
Value 0.30 -> RGBA [ 0 0 0 255]
Value 0.40 -> RGBA [ 0 0 0 255]
Value 0.50 -> RGBA [ 1 1 1 255]
Value 0.60 -> RGBA [ 1 1 1 255]
Value 0.70 -> RGBA [ 1 1 1 255]
Value 0.80 -> RGBA [ 1 1 1 255]
Value 0.90 -> RGBA [ 1 1 1 255]
Value 1.00 -> RGBA [ 2 2 2 255]
Scale: 2
Value 0.00 -> RGBA [ 0 0 0 255]
Value 0.10 -> RGBA [ 0 0 0 255]
Value 0.20 -> RGBA [ 0 0 0 255]
Value 0.30 -> RGBA [ 0 0 0 255]
Value 0.40 -> RGBA [ 0 0 0 255]
Value 0.50 -> RGBA [ 1 1 1 255]
Value 0.60 -> RGBA [ 1 1 1 255]
Value 0.70 -> RGBA [ 1 1 1 255]
Value 0.80 -> RGBA [ 1 1 1 255]
Value 0.90 -> RGBA [ 1 1 1 255]
Value 1.00 -> RGBA [ 2 2 2 255]
Scale: 3
Value 0.00 -> RGBA [ 0 0 0 255]
Value 0.10 -> RGBA [ 0 0 0 255]
Value 0.20 -> RGBA [ 0 0 0 255]
Value 0.30 -> RGBA [ 0 0 0 255]
Value 0.40 -> RGBA [ 1 1 1 255]
Value 0.50 -> RGBA [ 1 1 1 255]
Value 0.60 -> RGBA [ 1 1 1 255]
Value 0.70 -> RGBA [ 2 2 2 255]
Value 0.80 -> RGBA [ 2 2 2 255]
Value 0.90 -> RGBA [ 2 2 2 255]
Value 1.00 -> RGBA [ 2 2 2 255]
The output for scale None and 2 have the same (incorrect) output. Since you have three colors you would expect that the color changes from RGBA(0, 0, 0, 255) to RGBA(1, 1, 1, 255) at value 0.33. As you can see this is not the case: at value 0.40 the color is still RGBA(0, 0, 0, 255)). For scale 3 the output is correct.
The fix is simple: change scale = lut.shape[0] - 1 to scale = lut.shape[0]