16bit color index; proper rounding of index values

This commit is contained in:
Philip Eisenlohr 2020-08-05 10:08:48 -04:00
parent 0aaba487d7
commit e4103564a9
1 changed files with 9 additions and 3 deletions

View File

@ -168,7 +168,7 @@ class Colormap(mpl.colors.ListedColormap):
Parameters Parameters
---------- ----------
field : np.array of shape(:,:) field : numpy.array of shape(:,:)
Data to be shaded. Data to be shaded.
bounds : iterable of len(2), optional bounds : iterable of len(2), optional
Colormap value range (low,high). Colormap value range (low,high).
@ -193,8 +193,14 @@ class Colormap(mpl.colors.ListedColormap):
if delta * 1e8 <= avg: # delta is similar to numerical noise if delta * 1e8 <= avg: # delta is similar to numerical noise
hi,lo = hi+0.5*avg,lo-0.5*avg # extend range to have actual data centered within hi,lo = hi+0.5*avg,lo-0.5*avg # extend range to have actual data centered within
return Image.fromarray((np.dstack((self.colors[(np.clip((field-lo)/(hi-lo),0.0,1.0)*(N-1)).astype(np.uint8),:3], return Image.fromarray(
mask.astype(float)))*255).astype(np.uint8), 'RGBA') (np.dstack((
self.colors[(np.round(np.clip((field-lo)/(hi-lo),0.0,1.0))*(N-1)).astype(np.uint16),:3],
mask.astype(float)
)
)*255
).astype(np.uint8),
mode='RGBA')
def show(self,aspect=10,vertical=False): def show(self,aspect=10,vertical=False):