added multiplication as color repeat functionality
This commit is contained in:
parent
efd9b37235
commit
6bd23715b8
|
@ -63,6 +63,16 @@ class Colormap(mpl.colors.ListedColormap):
|
|||
"""Concatenate (in-place)."""
|
||||
return self.__add__(other)
|
||||
|
||||
def __mul__(self, factor: int) -> 'Colormap':
|
||||
"""Repeat."""
|
||||
return Colormap(np.broadcast_to(self.colors,(factor,)+self.colors.shape)
|
||||
.reshape((factor*self.colors.shape[0],)+self.colors.shape[1:]),
|
||||
f'{self.name}*{factor}')
|
||||
|
||||
def __imul__(self, factor: int) -> 'Colormap':
|
||||
"""Repeat (in-place)."""
|
||||
return self.__mul__(factor)
|
||||
|
||||
def __invert__(self) -> 'Colormap':
|
||||
"""Reverse."""
|
||||
return self.reversed()
|
||||
|
|
|
@ -140,6 +140,11 @@ class TestColormap:
|
|||
c += c
|
||||
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',[
|
||||
(8,'gray',0.5,[0.5,0.5,0.5]),
|
||||
(17,'gray',0.5,[0.5,0.5,0.5]),
|
||||
|
|
Loading…
Reference in New Issue