{"id":3001,"date":"2011-12-09T09:10:13","date_gmt":"2011-12-09T14:10:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=3001"},"modified":"2021-09-22T15:27:20","modified_gmt":"2021-09-22T19:27:20","slug":"a-vivid-colormap","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/12\/09\/a-vivid-colormap\/","title":{"rendered":"A Vivid Colormap"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/20848-vivid-colormap (link no longer works)\">Vivid Colormap<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/90537\">Joseph Kirk<\/a>.\r\n\r\nGood uses of colors can help convey ideas effectively. It can help you accentuate certain concepts. Or you may need to use\r\na gradient color that translates well when printed in gray scale. Joseph's entry really caught my attention. As the name suggests,\r\nit produces quite a vivid colormap. The idea is ingenious; he creates a gradient within each color, and that produces an accent\r\nat each level.\r\n\r\nLet's see how it works. We'll first create a blue and red diverging color map, which gradually changes from blue to red with\r\nwhite in the center. We'll use the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/peaks.html\"><tt>peaks<\/tt><\/a> function as the sample image.\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\"><span style=\"color: #228b22;\">% Create 13-level blue\/red diverging color map:<\/span>\r\nlevel = 13; n = ceil(level\/2);\r\ncmap1 = [linspace(1, 1, n); linspace(0, 1, n); linspace(0, 1, n)]';\r\ncmap2 = [linspace(1, 0, n); linspace(1, 0, n); linspace(1, 1, n)]';\r\ncmap = [cmap1; cmap2(2:end, :)];\r\n\r\nimagesc(peaks(500));\r\ncolormap(vivid(cmap)); caxis([-8 8]);\r\ncolorbar<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_vivid_colormap\/potw_vivid_colormap_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nNotice how vivid it looks! <tt>vivid<\/tt> also has additional options to change the level of gradients.\r\n\r\nLess vivid:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">colormap(vivid(cmap, [.4, .6]));<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_vivid_colormap\/potw_vivid_colormap_02.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nMore vivid:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">colormap(vivid(cmap, [0, 1]));<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_vivid_colormap\/potw_vivid_colormap_03.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nYou can also get the regular colormap behavior:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">colormap(vivid(cmap, [.5 .5]));<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_vivid_colormap\/potw_vivid_colormap_04.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\n<b>More on Colormaps<\/b>\r\n\r\nAs I was writing this post, I learned quite a bit about colormaps. MATLAB has a set of standard colormaps described <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/colormap.html#f19-357282\">here<\/a>. There are a few File Exchange entries that create additional colormaps, such as <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt\"><tt>cbrewer<\/tt><\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30564-othercolor\"><tt>othercolor<\/tt><\/a>, and <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/289-ellipse-m\">Color Palette Tables<\/a>. There are also colormaps that would look nice when printed on a grayscale printer - Lab color scale and <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/12-central-diff-m\"><tt>colorGray<\/tt><\/a>.\r\n\r\nI also found a couple of entries that would have helped me with creating the blue\/red diverging colormap - <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4058-bluewhitered\"><tt>bluewhitered<\/tt><\/a> and <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/17552-makecolormap\"><tt>makeColorMap<\/tt><\/a>.\r\n\r\n<b>Comments<\/b>\r\n\r\nCheck out all the File Exchange entries on <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=colormap\">colormaps<\/a>! If you have your favorite colormap, let us know <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=3001#respond\">here<\/a> or try Joseph's <tt>vivid<\/tt> and leave a comment for him.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_3558e39145e5486ca9cf6b95ea84c18f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='3558e39145e5486ca9cf6b95ea84c18f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3558e39145e5486ca9cf6b95ea84c18f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2011 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.13<\/p>\r\n\r\n<\/div>\r\n<!--\r\n3558e39145e5486ca9cf6b95ea84c18f ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007 % Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/20848-vivid-colormap Vivid % Colormap> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/90537 Joseph % Kirk>.\r\n%\r\n% Good uses of colors can help convey ideas effectively. It can help you\r\n% accentuate certain concepts. Or you may need to use a gradient color that\r\n% translates well when printed in gray scale. Joseph's entry really caught\r\n% my attention. As the name suggests, it produces quite a vivid colormap.\r\n% The idea is ingenious; he creates a gradient within each color, and that\r\n% produces an accent at each level.\r\n%\r\n% Let's see how it works. We'll first create a blue and red diverging color\r\n% map, which gradually changes from blue to red with white in the center.\r\n% We'll use the <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/peaks.html % |peaks|> function as the sample image.\r\n\r\n% Create 13-level blue\/red diverging color map:\r\nlevel = 13; n = ceil(level\/2);\r\ncmap1 = [linspace(1, 1, n); linspace(0, 1, n); linspace(0, 1, n)]';\r\ncmap2 = [linspace(1, 0, n); linspace(1, 0, n); linspace(1, 1, n)]';\r\ncmap = [cmap1; cmap2(2:end, :)];\r\n\r\nimagesc(peaks(500));\r\ncolormap(vivid(cmap)); caxis([-8 8]);\r\ncolorbar\r\n\r\n%%\r\n% Notice how vivid it looks! |vivid| also has additional options to change\r\n% the level of gradients.\r\n%\r\n% Less vivid:\r\n\r\ncolormap(vivid(cmap, [.4, .6]));\r\n\r\n%%\r\n% More vivid:\r\n\r\ncolormap(vivid(cmap, [0, 1]));\r\n\r\n%%\r\n% You can also get the regular colormap behavior:\r\n\r\ncolormap(vivid(cmap, [.5 .5]));\r\n\r\n%%\r\n% *More on Colormaps*\r\n%\r\n% As I was writing this post, I learned quite a bit about colormaps. MATLAB\r\n% has a set of standard colormaps described\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/colormap.html#f19-357282 % here>. There are a few File Exchange entries that create additional\r\n% colormaps, such as\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt |cbrewer|>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30564-othercolor |othercolor|>,\r\n% and <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/289-ellipse-m Color % Palette Tables>. There are also colormaps that would look nice when\r\n% printed on a grayscale printer -\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/11037 Lab color % scale> and <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/12-central-diff-m % |colorGray|>.\r\n%\r\n% I also found a couple of entries that would have helped me with creating\r\n% the blue\/red diverging colormap -\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4058-bluewhitered |bluewhitered|>\r\n% and <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/17552-makecolormap % |makeColorMap|>.\r\n%\r\n% *Comments*\r\n%\r\n% Check out all the File Exchange entries on\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=colormap % colormaps>! If you have your favorite colormap, let us know\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=3001#respond here> or try Joseph's\r\n% |vivid| and leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/20848-vivid-colormap#comments % comment> for him.\r\n\r\n##### SOURCE END ##### 3558e39145e5486ca9cf6b95ea84c18f\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nJiro's pick this week is Vivid Colormap by Joseph Kirk.\r\n\r\nGood uses of colors can help convey ideas effectively. It can help you accentuate certain concepts. Or you may need to use\r\na gradient... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/12\/09\/a-vivid-colormap\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3001"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=3001"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3001\/revisions"}],"predecessor-version":[{"id":14268,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3001\/revisions\/14268"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=3001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=3001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=3001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}