{"id":4762,"date":"2023-07-05T20:00:00","date_gmt":"2023-07-05T11:00:00","guid":{"rendered":"https:\/\/python-academia.com\/en\/?p=4762"},"modified":"2023-06-09T06:57:13","modified_gmt":"2023-06-08T21:57:13","slug":"matplotlib-colorlist","status":"publish","type":"post","link":"https:\/\/python-academia.com\/en\/matplotlib-colorlist\/","title":{"rendered":"[matplotlib]List of Color Names"},"content":{"rendered":"\n<p>This article shows <span class=\"st-mymarker-s\">list of color names in matplotlib<\/span>.<\/p>\n\n\n\n<div class=\"wp-block-st-blocks-midashi-box freebox has-title\" style=\"background-color:#eceff1;border-color:#263238;border-radius:0 5px 5px 5px\"><p class=\"p-free\" style=\"border-color:#263238;font-weight:bold\"><span class=\"p-entry-f\" style=\"color:#ffffff;font-weight:bold;background-color:#263238;border-radius:0 0 5px 0\"><i class=\"st-fa st-svg-file-text-o st-css-no\" aria-hidden=\"\"><\/i>Contents<\/span><\/p><div class=\"free-inbox\">\n<p><\/p>\n\n\n\n<ul><li>List of Color Names<\/li><li>How to Get a List of Colors<\/li><li>[Supplement]How to Plot a Graph using a Color List<\/li><\/ul>\n\n\n\n<p><\/p>\n<\/div><\/div>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">List of Color Names<\/h2>\n\n\n\n<p>I show <span class=\"st-mymarker-s\">the list of colors available in matplotlib<\/span>.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Three groups of colors can be specified : <span class=\"st-mymarker-s\">Base Colors, Tableau Palettes, and CSS Colors<\/span>.<\/p>\n\n\n\n<p><span class=\"st-mymarker-s\">Color code<\/span> can also be used.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I will show each color group in order.<\/p>\n\n\n\n<p>The figures are taken from the <a href=\"https:\/\/matplotlib.org\/stable\/gallery\/color\/named_colors.html\" target=\"_blank\" rel=\"noreferrer noopener\">official documentation<\/a>.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Base Colors<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote has-text-align-center\"><p><img decoding=\"async\" width=\"566\" height=\"124\" class=\"wp-image-4780\" style=\"width: 600px;\" src=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-1.jpg\" alt=\"\" srcset=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-1.jpg 566w, https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-1-300x66.jpg 300w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/p><\/blockquote>\n\n\n\n<p>Base Color can be specified by a single letter.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tableau Palette<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote has-text-align-center\"><p><img decoding=\"async\" width=\"391\" height=\"169\" class=\"wp-image-4782\" style=\"width: 600px;\" src=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-2.jpg\" alt=\"\" srcset=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-2.jpg 391w, https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-2-300x130.jpg 300w\" sizes=\"(max-width: 391px) 100vw, 391px\" \/><\/p><p><\/p><\/blockquote>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CSS Colors<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote has-text-align-center\"><p><img decoding=\"async\" width=\"731\" height=\"741\" class=\"wp-image-4785\" style=\"width: 600px;\" src=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-3.jpg\" alt=\"\" srcset=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-3.jpg 731w, https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-3-296x300.jpg 296w, https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/07\/matplotlib-color_1-3-60x60.jpg 60w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p><p><\/p><\/blockquote>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Color code<\/h3>\n\n\n\n<p><span class=\"st-mymarker-s\">The color code is the code used to specify colors on a website<\/span>.<\/p>\n\n\n\n<p>It is described as a six-digit hexadecimal number.<\/p>\n\n\n\n<p>For example, white is #000000 and black is #FFFFFFF.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p style=\"color:#666;margin-bottom:5px;\">sponsored link<\/p>\n\n<table>\n<tbody>\n<tr>\n<td>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6354467409705666\"\n     crossorigin=\"anonymous\"><\/script>\n<!-- py-article-doubleA -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:336px;height:300px\"\n     data-ad-client=\"ca-pub-6354467409705666\"\n     data-ad-slot=\"1820454727\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/td>\n\n<td>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6354467409705666\"\n     crossorigin=\"anonymous\"><\/script>\n<!-- py-article-doubleB -->\n<ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:336px;height:300px\"\n     data-ad-client=\"ca-pub-6354467409705666\"\n     data-ad-slot=\"3395043238\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">How to Get a List of Colors<\/h2>\n\n\n\n<p>Next, I show <span class=\"st-mymarker-s\">how to get a list of colors.<\/span><\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The following code can be used to get a list of each color group.<\/p>\n\n\n\n<ul><li>Base Colors : matplotlib.colors.BASE_COLORS<\/li><li>Tableau Palette : matplotlib.colors.TABLEAU_COLORS<\/li><li>CSS Colors : matplotlib.colors.CSS4_COLORS<\/li><\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In the following section, I show the example code.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Base Colors<\/h3>\n\n\n\n<p>This is the example code to get a list of Base Colors.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers language-Python\"><code>import matplotlib.colors as mcolors\nimport pprint\n\nbase_colors = mcolors.BASE_COLORS\n\npprint.pprint(base_colors)\n\"\"\"\n{'b': (0, 0, 1),\n 'c': (0, 0.75, 0.75),\n 'g': (0, 0.5, 0),\n 'k': (0, 0, 0),\n 'm': (0.75, 0, 0.75),\n 'r': (1, 0, 0),\n 'w': (1, 1, 1),\n 'y': (0.75, 0.75, 0)}\n\"\"\"\n\npprint.pprint(list(base_colors.keys()))\n\"\"\"\n&#091;'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n\"\"\"<\/code><\/pre>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The data is dictionary type.<\/p>\n\n\n\n<p>The &#8220;key&#8221; is &#8220;color name&#8221; and the &#8220;value&#8221; is a &#8220;tuple of RGB values&#8221;.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>&gt; pprint.pprint(list(base_colors.keys()))<\/p>\n\n\n\n<p>The list of keys is got using &#8220;dictionary&#8221;.keys( ).<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tableau Palette<\/h3>\n\n\n\n<p>This is the example code to get a list of Tableau Palette.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers language-Python\"><code>import matplotlib.colors as mcolors\nimport pprint\n\ntab_colors = mcolors.TABLEAU_COLORS\n\npprint.pprint(tab_colors)\n\"\"\"\nOrderedDict(&#091;('tab:blue', '#1f77b4'),\n             ('tab:orange', '#ff7f0e'),\n             ('tab:green', '#2ca02c'),\n             ('tab:red', '#d62728'),\n             ('tab:purple', '#9467bd'),\n             ('tab:brown', '#8c564b'),\n             ('tab:pink', '#e377c2'),\n             ('tab:gray', '#7f7f7f'),\n             ('tab:olive', '#bcbd22'),\n             ('tab:cyan', '#17becf')])\n\"\"\"\n\npprint.pprint(list(tab_colors.keys()))\n\"\"\"\n&#091;'tab:blue',\n 'tab:orange',\n 'tab:green',\n 'tab:red',\n 'tab:purple',\n 'tab:brown',\n 'tab:pink',\n 'tab:gray',\n 'tab:olive',\n 'tab:cyan']\n\"\"\"<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CSS Colors<\/h3>\n\n\n\n<p>This is the example code to get a list of CSS Colors.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers language-Python\"><code>import matplotlib.colors as mcolors\nimport pprint\n\ncss_colors = mcolors.CSS4_COLORS\n\npprint.pprint(css_colors)\n\"\"\"\n{'aliceblue': '#F0F8FF',\n 'antiquewhite': '#FAEBD7',\n 'aqua': '#00FFFF',\n 'aquamarine': '#7FFFD4',\n 'azure': '#F0FFFF',\n \n \u2026\n\n 'wheat': '#F5DEB3',\n 'white': '#FFFFFF',\n 'whitesmoke': '#F5F5F5',\n 'yellow': '#FFFF00',\n 'yellowgreen': '#9ACD32'}\n\"\"\"\n\npprint.pprint(list(css_colors.keys()))\n\"\"\"\n&#091;'aliceblue',\n 'antiquewhite',\n 'aqua',\n 'aquamarine',\n 'azure',\n \n \u2026\n \n 'wheat',\n 'white',\n 'whitesmoke',\n 'yellow',\n 'yellowgreen']\n\"\"\"<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p style=\"color:#666;margin-bottom:5px;\">sponsored link<\/p>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6354467409705666\"\n     crossorigin=\"anonymous\"><\/script>\n<!-- py-article-display -->\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-client=\"ca-pub-6354467409705666\"\n     data-ad-slot=\"6239864271\"\n     data-ad-format=\"auto\"\n     data-full-width-responsive=\"true\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">[Supplement]How to Plot a Graph using a Color List<\/h2>\n\n\n\n<p>I show <span class=\"st-mymarker-s\">how to plot a graph using a color list.<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers language-Python\"><code>import matplotlib.pyplot as plt\nimport matplotlib.colors as mcolors\nimport numpy as np\n \ntab_colors = mcolors.TABLEAU_COLORS\ncolorlist = list(tab_colors.keys())\n\nx = np.arange(0, len(colorlist))\ny = np.repeat(1, len(colorlist))\n\nfig = plt.figure(figsize = (12,3), facecolor='lightblue')\n\nplt.bar(x, y, color=colorlist, tick_label=colorlist, align=\"center\")\nplt.show()<\/code><\/pre>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The above code generates the following graph.<\/p>\n\n\n<div class=\"wp-block-image is-style-st-photo-shadow\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"706\" height=\"194\" src=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/05\/matplotlib-color_2-1.png\" alt=\"\" class=\"wp-image-4798\" srcset=\"https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/05\/matplotlib-color_2-1.png 706w, https:\/\/python-academia.com\/en\/wp-content\/uploads\/sites\/2\/2023\/05\/matplotlib-color_2-1-300x82.png 300w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>&gt; tab_colors = mcolors.TABLEAU_COLORS<br>&gt; colorlist = list(tab_colors.keys())<\/p>\n\n\n\n<p>The dictionary type data of Tableau Palette is got and converted to the list.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The following article explains how to create a bar plot.<\/p>\n\n\n\n<p class=\"is-style-st-paragraph-memo\"><a href=\"https:\/\/python-academia.com\/en\/matplotlib-bargraph\/\">How to Create a Bar Plot<\/a><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p style=\"color:#666;margin-bottom:5px;\">sponsored link<\/p>\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6354467409705666\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-matched-content-rows-num=\"4,2\"\n     data-matched-content-columns-num=\"1,4\"\n     data-matched-content-ui-type=\"image_stacked,image_stacked\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-6354467409705666\"\n     data-ad-slot=\"2243394422\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>This article shows list of color names in matplotlib. List of Color Names I show the list of colors  &#8230; <\/p>\n","protected":false},"author":1,"featured_media":5581,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[20,21],"_links":{"self":[{"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/posts\/4762"}],"collection":[{"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/comments?post=4762"}],"version-history":[{"count":84,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/posts\/4762\/revisions"}],"predecessor-version":[{"id":5620,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/posts\/4762\/revisions\/5620"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/media\/5581"}],"wp:attachment":[{"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/media?parent=4762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/categories?post=4762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python-academia.com\/en\/wp-json\/wp\/v2\/tags?post=4762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}