Merge branch 'colormap-repeat' into 'development'

added multiplication as color repeat functionality

See merge request damask/DAMASK!508
This commit is contained in:
Philip Eisenlohr 2022-01-24 20:58:46 +00:00
commit d9a712abf7
2 changed files with 13 additions and 0 deletions

View File

@ -63,6 +63,14 @@ class Colormap(mpl.colors.ListedColormap):
"""Concatenate (in-place).""" """Concatenate (in-place)."""
return self.__add__(other) return self.__add__(other)
def __mul__(self, factor: int) -> 'Colormap':
"""Repeat."""
return Colormap(np.vstack([self.colors]*factor),f'{self.name}*{factor}')
def __imul__(self, factor: int) -> 'Colormap':
"""Repeat (in-place)."""
return self.__mul__(factor)
def __invert__(self) -> 'Colormap': def __invert__(self) -> 'Colormap':
"""Reverse.""" """Reverse."""
return self.reversed() return self.reversed()

View File

@ -140,6 +140,11 @@ class TestColormap:
c += c c += c
assert (np.allclose(c.colors[:len(c.colors)//2],c.colors[len(c.colors)//2:])) assert (np.allclose(c.colors[:len(c.colors)//2],c.colors[len(c.colors)//2:]))
def test_mul(self):
c = o = Colormap.from_predefined('jet')
o *= 2
assert c+c == o
@pytest.mark.parametrize('N,cmap,at,result',[ @pytest.mark.parametrize('N,cmap,at,result',[
(8,'gray',0.5,[0.5,0.5,0.5]), (8,'gray',0.5,[0.5,0.5,0.5]),
(17,'gray',0.5,[0.5,0.5,0.5]), (17,'gray',0.5,[0.5,0.5,0.5]),