FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

copy a color map object does not isolate changes to cm · Issue #8299 · matplotlib/matplotlib · GitHub

Repository navigation

copy a color map object does not isolate changes to cm #8299

Description

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).

Activity

  1. added this to the milestone on Mar 15, 2017
  2. tacaswell commented on Mar 15, 2017

    MemberAuthor

    Exact work:

    • implement __copy__ and maybe __deepcopy__ on ColorMap

    Tagging as medium because the color map code is a bit convoluted .

  3. bendichter commented on Mar 15, 2017

    I can reproduce this issue with:

    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?

  4. dopplershift commented on Mar 15, 2017

    Contributor

    Implementing __copy__ should be enough to get the desired behavior.

  5. added a commit that references this issue on Mar 24, 2017
  6. added a commit that references this issue on May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL