enthought / enthought/mayavi

BUG: LUT / colormap setting bug

Open
#622 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

There is a strange discrepancy when setting a colormap:
```
import numpy as np
from mayavi import mlab
fig = mlab.figure(bgcolor=(1., 1., 1.))
scalars = [1, 0, 2]
cmap = np.array([(1, 0, 0, 1), (0, 0, 0, 1), (1, 1, 1, 1)])
x, y, z = [0, 1, 0], [0, 0, 1], [-1, -1, -1]
tris = [[0, 1, 2]]
surf = mlab.triangular_mesh(x, y, z, tris, scalars=scalars)
l_m = surf.module_manager.scalar_lut_manager

# Method 1: set .table directly (works)
l_m.lut.table = cmap * 255

# Method 2: load_lut_from_list: requires setting data_range
# l_m.load_lut_from_list(cmap)
# l_m.data_range = [0, 2 + np.finfo(float).eps * 2]

# Method 3: from_array: does not update (maybe some .update() required?)
# l_m.lut.table.from_array(cmap * 255.)
```
Method 1 above works and produces (And checking `l_m.data_range`, it is `[0. 2.]`):

![snapshot](https://user-images.githubusercontent.com/2365790/37727224-a8c0e4ce-2d0d-11e8-90a1-52742f490af8.png)

Method 2 without setting data range produces (and checking the value of `l_m.data_range` it is again `[0. 2.]`):

![snapshot](https://user-images.githubusercontent.com/2365790/37727271-c63b596c-2d0d-11e8-950f-aab1aaf8b1fd.png)

However, uncommenting the line to set the upper limit to `eps` beyond 2. produces the correct output (using 2. itself does not!):

![snapshot](https://user-images.githubusercontent.com/2365790/37727320-e73a9d12-2d0d-11e8-9d8b-d4ccefb7a064.png)

The third method does not seem to work at all, maybe because it's operating at too low a level, similar to #488. It can thus probably be ignored since there are suitable workarounds.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.