{"action":"created","comment":{"url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/comments/62789779","id":62789779,"diff_hunk":"@@ -62,55 +65,201 @@\n import numpy as np\n from numpy import ma\n import matplotlib.cbook as cbook\n-from ._color_data import XKCD_COLORS, CSS4_COLORS\n+from ._color_data import BASE_COLORS, CSS4_COLORS, XKCD_COLORS\n \n-# for back copatibility\n-cnames = CSS4_COLORS\n \n-COLOR_NAMES = {'xkcd': XKCD_COLORS,\n-               'css4': CSS4_COLORS}\n+class _ColorMapping(dict):\n+    def __init__(self, mapping):\n+        super(_ColorMapping, self).__init__(mapping)\n+        self._cache = {}\n \n+    def __setitem__(self, key, value):\n+        super(_ColorMapping, self).__setitem__(key, value)\n+        self._cache.clear()\n \n-def is_color_like(c):\n-    'Return *True* if *c* can be converted to *RGB*'\n-\n-    # Special-case the N-th color cycle syntax, because its parsing\n-    # needs to be deferred.  We may be reading a value from rcParams\n-    # here before the color_cycle rcParam has been parsed.\n-    if isinstance(c, bytes):\n-        match = re.match(b'^C[0-9]$', c)\n-        if match is not None:\n-            return True\n-    elif isinstance(c, six.text_type):\n-        match = re.match('^C[0-9]$', c)\n-        if match is not None:\n-            return True\n+    def __delitem__(self, key, value):\n+        super(_ColorMapping, self).__delitem__(key, value)\n+        self._cache.clear()\n \n-    try:\n-        colorConverter.to_rgb(c)\n+\n+_colors_full_map = {}\n+# Set by reverse priority order.\n+_colors_full_map.update(XKCD_COLORS)\n+_colors_full_map.update(CSS4_COLORS)\n+_colors_full_map.update(BASE_COLORS)\n+_colors_full_map = _ColorMapping(_colors_full_map)\n+\n+\n+def get_named_colors_mapping():\n+    \"\"\"Return the global mapping of names to named colors.\n+    \"\"\"\n+    return _colors_full_map\n+\n+\n+def _is_nth_color(c):\n+    \"\"\"Return whether `c` can be interpreted as an item in the color cycle.\n+    \"\"\"\n+    return isinstance(c, six.string_types) and re.match(r\"\\AC[0-9]\\Z\", c)\n+\n+\n+def is_color_like(c):\n+    \"\"\"Return whether `c` can be interpreted as an RGB(A) color.\n+    \"\"\"\n+    # Special-case nth color syntax because it cannot be parsed during\n+    # setup.\n+    if _is_nth_color(c):\n         return True\n+    try:\n+        to_rgba(c)\n     except ValueError:\n         return False\n+    else:\n+        return True\n \n \n-def rgb2hex(rgb):\n-    'Given an rgb or rgba sequence of 0-1 floats, return the hex string'\n-    a = '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]])\n-    return a\n+def to_rgba(c, alpha=None):\n+    \"\"\"Convert `c` to an RGBA color.\n \n+    If `alpha` is not `None`, it forces the alpha value.\n+    \"\"\"\n+    # Special-case nth color syntax because it should not be cached.\n+    if _is_nth_color(c):\n+        from matplotlib import rcParams\n+        from matplotlib.rcsetup import cycler\n+        prop_cycler = rcParams['axes.prop_cycle']\n+        if prop_cycler is None and 'axes.color_cycle' in rcParams:\n+            clist = rcParams['axes.color_cycle']\n+            prop_cycler = cycler('color', clist)\n+        colors = prop_cycler._transpose()['color']","path":"lib/matplotlib/colors.py","position":126,"original_position":126,"commit_id":"6ab87c993983b84ac042ff34c6f8b2561ac84ef9","original_commit_id":"6ab87c993983b84ac042ff34c6f8b2561ac84ef9","user":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"body":"This was copypasted from the previous implementation.  I don't know anything about `cycler`, but I guess `prop_cycler._transpose().get('color', 'k')` would work?","created_at":"2016-05-11T04:15:16Z","updated_at":"2016-05-11T04:15:16Z","html_url":"https://github.com/matplotlib/matplotlib/pull/6382#discussion_r62789779","pull_request_url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382","_links":{"self":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/comments/62789779"},"html":{"href":"https://github.com/matplotlib/matplotlib/pull/6382#discussion_r62789779"},"pull_request":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382"}}},"pull_request":{"url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382","id":69256903,"html_url":"https://github.com/matplotlib/matplotlib/pull/6382","diff_url":"https://github.com/matplotlib/matplotlib/pull/6382.diff","patch_url":"https://github.com/matplotlib/matplotlib/pull/6382.patch","issue_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6382","number":6382,"state":"open","locked":false,"title":"New color conversion machinery.","user":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"body":"The main goal is to support `#rrggbbaa` hex color spec (#5461, #6196).  The API is also considerably simplified: the conversion API is now reduced to\r\n- `is_color_like(c)`\r\n- `to_rgba(c, alpha=None)`\r\n- `to_rgba_array(c, alpha=None)`\r\n- `to_hex(c, alpha=None)`\r\n\r\nFull backwards compatibility is maintained (perhaps the compatibility layer should be deprecated in a later PR).","created_at":"2016-05-08T00:26:11Z","updated_at":"2016-05-11T04:15:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4c314189e8b52ebad078c20dead813eb55fe78c","assignee":null,"milestone":{"url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/12","html_url":"https://github.com/matplotlib/matplotlib/milestones/2.1%20(next%20point%20release)","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/12/labels","id":534144,"number":12,"title":"2.1 (next point release)","description":"Next feature release.\r\n\r\nBig ticket items:\r\n\r\n - MEP 22/27\r\n - traitlets","creator":{"login":"tacaswell","id":199813,"avatar_url":"https://avatars.githubusercontent.com/u/199813?v=3","gravatar_id":"","url":"https://api.github.com/users/tacaswell","html_url":"https://github.com/tacaswell","followers_url":"https://api.github.com/users/tacaswell/followers","following_url":"https://api.github.com/users/tacaswell/following{/other_user}","gists_url":"https://api.github.com/users/tacaswell/gists{/gist_id}","starred_url":"https://api.github.com/users/tacaswell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tacaswell/subscriptions","organizations_url":"https://api.github.com/users/tacaswell/orgs","repos_url":"https://api.github.com/users/tacaswell/repos","events_url":"https://api.github.com/users/tacaswell/events{/privacy}","received_events_url":"https://api.github.com/users/tacaswell/received_events","type":"User","site_admin":false},"open_issues":482,"closed_issues":371,"state":"open","created_at":"2014-01-13T03:21:09Z","updated_at":"2016-05-10T10:05:55Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382/commits","review_comments_url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382/comments","review_comment_url":"https://api.github.com/repos/matplotlib/matplotlib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6382/comments","statuses_url":"https://api.github.com/repos/matplotlib/matplotlib/statuses/6ab87c993983b84ac042ff34c6f8b2561ac84ef9","head":{"label":"anntzer:rgba-support","ref":"rgba-support","sha":"6ab87c993983b84ac042ff34c6f8b2561ac84ef9","user":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"repo":{"id":7439715,"name":"matplotlib","full_name":"anntzer/matplotlib","owner":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anntzer/matplotlib","description":"","fork":true,"url":"https://api.github.com/repos/anntzer/matplotlib","forks_url":"https://api.github.com/repos/anntzer/matplotlib/forks","keys_url":"https://api.github.com/repos/anntzer/matplotlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anntzer/matplotlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anntzer/matplotlib/teams","hooks_url":"https://api.github.com/repos/anntzer/matplotlib/hooks","issue_events_url":"https://api.github.com/repos/anntzer/matplotlib/issues/events{/number}","events_url":"https://api.github.com/repos/anntzer/matplotlib/events","assignees_url":"https://api.github.com/repos/anntzer/matplotlib/assignees{/user}","branches_url":"https://api.github.com/repos/anntzer/matplotlib/branches{/branch}","tags_url":"https://api.github.com/repos/anntzer/matplotlib/tags","blobs_url":"https://api.github.com/repos/anntzer/matplotlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anntzer/matplotlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anntzer/matplotlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/anntzer/matplotlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anntzer/matplotlib/statuses/{sha}","languages_url":"https://api.github.com/repos/anntzer/matplotlib/languages","stargazers_url":"https://api.github.com/repos/anntzer/matplotlib/stargazers","contributors_url":"https://api.github.com/repos/anntzer/matplotlib/contributors","subscribers_url":"https://api.github.com/repos/anntzer/matplotlib/subscribers","subscription_url":"https://api.github.com/repos/anntzer/matplotlib/subscription","commits_url":"https://api.github.com/repos/anntzer/matplotlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/anntzer/matplotlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/anntzer/matplotlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/anntzer/matplotlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/anntzer/matplotlib/contents/{+path}","compare_url":"https://api.github.com/repos/anntzer/matplotlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anntzer/matplotlib/merges","archive_url":"https://api.github.com/repos/anntzer/matplotlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anntzer/matplotlib/downloads","issues_url":"https://api.github.com/repos/anntzer/matplotlib/issues{/number}","pulls_url":"https://api.github.com/repos/anntzer/matplotlib/pulls{/number}","milestones_url":"https://api.github.com/repos/anntzer/matplotlib/milestones{/number}","notifications_url":"https://api.github.com/repos/anntzer/matplotlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anntzer/matplotlib/labels{/name}","releases_url":"https://api.github.com/repos/anntzer/matplotlib/releases{/id}","deployments_url":"https://api.github.com/repos/anntzer/matplotlib/deployments","created_at":"2013-01-04T12:08:11Z","updated_at":"2015-05-05T17:32:26Z","pushed_at":"2016-05-10T18:02:34Z","git_url":"git://github.com/anntzer/matplotlib.git","ssh_url":"git@github.com:anntzer/matplotlib.git","clone_url":"https://github.com/anntzer/matplotlib.git","svn_url":"https://github.com/anntzer/matplotlib","homepage":"","size":284579,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"matplotlib:master","ref":"master","sha":"aeb6112a71c6d169be6ab0a824b69270ea9c0d02","user":{"login":"matplotlib","id":215947,"avatar_url":"https://avatars.githubusercontent.com/u/215947?v=3","gravatar_id":"","url":"https://api.github.com/users/matplotlib","html_url":"https://github.com/matplotlib","followers_url":"https://api.github.com/users/matplotlib/followers","following_url":"https://api.github.com/users/matplotlib/following{/other_user}","gists_url":"https://api.github.com/users/matplotlib/gists{/gist_id}","starred_url":"https://api.github.com/users/matplotlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matplotlib/subscriptions","organizations_url":"https://api.github.com/users/matplotlib/orgs","repos_url":"https://api.github.com/users/matplotlib/repos","events_url":"https://api.github.com/users/matplotlib/events{/privacy}","received_events_url":"https://api.github.com/users/matplotlib/received_events","type":"Organization","site_admin":false},"repo":{"id":1385122,"name":"matplotlib","full_name":"matplotlib/matplotlib","owner":{"login":"matplotlib","id":215947,"avatar_url":"https://avatars.githubusercontent.com/u/215947?v=3","gravatar_id":"","url":"https://api.github.com/users/matplotlib","html_url":"https://github.com/matplotlib","followers_url":"https://api.github.com/users/matplotlib/followers","following_url":"https://api.github.com/users/matplotlib/following{/other_user}","gists_url":"https://api.github.com/users/matplotlib/gists{/gist_id}","starred_url":"https://api.github.com/users/matplotlib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matplotlib/subscriptions","organizations_url":"https://api.github.com/users/matplotlib/orgs","repos_url":"https://api.github.com/users/matplotlib/repos","events_url":"https://api.github.com/users/matplotlib/events{/privacy}","received_events_url":"https://api.github.com/users/matplotlib/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matplotlib/matplotlib","description":"matplotlib: plotting with Python","fork":false,"url":"https://api.github.com/repos/matplotlib/matplotlib","forks_url":"https://api.github.com/repos/matplotlib/matplotlib/forks","keys_url":"https://api.github.com/repos/matplotlib/matplotlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matplotlib/matplotlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matplotlib/matplotlib/teams","hooks_url":"https://api.github.com/repos/matplotlib/matplotlib/hooks","issue_events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/events{/number}","events_url":"https://api.github.com/repos/matplotlib/matplotlib/events","assignees_url":"https://api.github.com/repos/matplotlib/matplotlib/assignees{/user}","branches_url":"https://api.github.com/repos/matplotlib/matplotlib/branches{/branch}","tags_url":"https://api.github.com/repos/matplotlib/matplotlib/tags","blobs_url":"https://api.github.com/repos/matplotlib/matplotlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matplotlib/matplotlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matplotlib/matplotlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/matplotlib/matplotlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matplotlib/matplotlib/statuses/{sha}","languages_url":"https://api.github.com/repos/matplotlib/matplotlib/languages","stargazers_url":"https://api.github.com/repos/matplotlib/matplotlib/stargazers","contributors_url":"https://api.github.com/repos/matplotlib/matplotlib/contributors","subscribers_url":"https://api.github.com/repos/matplotlib/matplotlib/subscribers","subscription_url":"https://api.github.com/repos/matplotlib/matplotlib/subscription","commits_url":"https://api.github.com/repos/matplotlib/matplotlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/matplotlib/matplotlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/matplotlib/matplotlib/contents/{+path}","compare_url":"https://api.github.com/repos/matplotlib/matplotlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matplotlib/matplotlib/merges","archive_url":"https://api.github.com/repos/matplotlib/matplotlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matplotlib/matplotlib/downloads","issues_url":"https://api.github.com/repos/matplotlib/matplotlib/issues{/number}","pulls_url":"https://api.github.com/repos/matplotlib/matplotlib/pulls{/number}","milestones_url":"https://api.github.com/repos/matplotlib/matplotlib/milestones{/number}","notifications_url":"https://api.github.com/repos/matplotlib/matplotlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/labels{/name}","releases_url":"https://api.github.com/repos/matplotlib/matplotlib/releases{/id}","deployments_url":"https://api.github.com/repos/matplotlib/matplotlib/deployments","created_at":"2011-02-19T03:17:12Z","updated_at":"2016-05-10T12:54:51Z","pushed_at":"2016-05-11T03:04:00Z","git_url":"git://github.com/matplotlib/matplotlib.git","ssh_url":"git@github.com:matplotlib/matplotlib.git","clone_url":"https://github.com/matplotlib/matplotlib.git","svn_url":"https://github.com/matplotlib/matplotlib","homepage":"http://matplotlib.org/","size":393926,"stargazers_count":3600,"watchers_count":3600,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1820,"mirror_url":null,"open_issues_count":870,"forks":1820,"open_issues":870,"watchers":3600,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382"},"html":{"href":"https://github.com/matplotlib/matplotlib/pull/6382"},"issue":{"href":"https://api.github.com/repos/matplotlib/matplotlib/issues/6382"},"comments":{"href":"https://api.github.com/repos/matplotlib/matplotlib/issues/6382/comments"},"review_comments":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382/comments"},"review_comment":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matplotlib/matplotlib/pulls/6382/commits"},"statuses":{"href":"https://api.github.com/repos/matplotlib/matplotlib/statuses/6ab87c993983b84ac042ff34c6f8b2561ac84ef9"}}}}