You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
copy a color map object does not isolate changes to cm #8299
If you do cm2 = copy.copy(cm) and the original color map has been used at least once, then the copy will share a reference to self._lut (which is what is used to __call__ to map from values -> rgba). Any calls to set_over, set_under, or set_bad will be shared by all copies (as they update self._lut in place).
import matplotlib.pyplot as plt
import copy
import numpy as np
%matplotlib inline
data = np.ma.masked_array([[1,2,3],[2,3,4]], mask=[[1,0,0],[0,0,0]])
cm = plt.cm.Reds
plt.imshow(data,cmap=cm)
plt.show()
cm2 = copy.copy(cm)
cm2.set_bad('b')
plt.imshow(data,cmap=cm)
In the second plot the image contains blue when it should remain white. copy.deepcopy works as expected, though. Would the solution be to have copy call deepcopy?
Activity
tacaswell commentedon Mar 15, 2017
Exact work:
__copy__and maybe__deepcopy__onColorMapTagging as medium because the color map code is a bit convoluted .
bendichter commentedon Mar 15, 2017
I can reproduce this issue with:
In the second plot the image contains blue when it should remain white. copy.deepcopy works as expected, though. Would the solution be to have copy call deepcopy?
dopplershift commentedon Mar 15, 2017
Implementing
__copy__should be enough to get the desired behavior.Issue matplotlib#8299, implemented copy, added test
Issue matplotlib#8375 and matplotlib#8299 fixed