Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ed55f4

Browse files
authored
Added __copy__ to Colormap
1 parent 1f173dd commit 3ed55f4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/matplotlib/colors.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,18 @@ def __call__(self, X, alpha=None, bytes=False):
529529
if vtype == 'scalar':
530530
rgba = tuple(rgba[0, :])
531531
return rgba
532-
532+
533+
def __copy__(self):
534+
"""Create new object with the same class and update attributes
535+
If object is initialized, copy the elements of _lut list
536+
"""
537+
cls = self.__class__
538+
newCMapObj = cls.__new__(cls)
539+
newCMapObj.__dict__.update(self.__dict__)
540+
if self._isinit:
541+
newCMapObj._lut = np.copy(self._lut)
542+
return newCMapObj
543+
533544
def set_bad(self, color='k', alpha=None):
534545
"""Set color to be used for masked values.
535546
"""

0 commit comments

Comments
 (0)