![]() |
Color Order for Line Plots
<div>
<nav> <ul> <li><a href="https://blogs.mathworks.com/cleve/2019/10/30/stability-of-kuramoto-oscillators/"><span>< Stability of Kuramoto Oscillators </span><span> < Previous</span></a></li> </ul> </nav> </div> <header> <h1> <a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/">Color Order for Line Plots</a> </h1> <p>Posted by <b><a href="https://www.mathworks.com/matlabcentral/profile/authors/349729-cleve-moler?s_tid=blg_to_profile">Cleve Moler</a></b>, <time>November 4, 2019</time> </p> </header> <div> <div> <div><p>Line plots with a color order from one of our color maps are useful, and pretty.</p><h3>Contents</h3><div><ul><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#6367f293-7ad1-4972-a5cf-0605cb8120ec">Default</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#79ab2bff-6b0c-4ef2-b2bd-82153857ffa8">Parula</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#ac830ae1-fdc2-49f5-8484-f7c254439318">Jet</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#863432e4-81ca-4768-abde-720716d12313">Copper</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#fb22d603-b3b9-47d2-80e1-0c9a2ed8dd1d">Peaks</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#b084ee88-43aa-45f9-a21b-c8e0fe91f4f8">Kuramoto</a></li><li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/#2a5eb1c7-c146-42bf-a164-d5a38a99fc04">Clean up</a></li></ul></div><h4>Default<a></a></h4><p>When you plot a two dimensional array, you ordinarily get a bunch of lines, colored like this.</p><pre> n = 19; plot(magic(n),<span>'linewidth'</span>,2) title(sprintf(<span>'magic(%d)'</span>,n)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_01.png"/> <p>The color of these lines is obtained by cycling through the "color order", which, by default, is these seven colors.</p><pre> rgb = get(gca,<span>'colororder'</span>) show_colors(rgb) </pre><pre>rgb = 0 0.4470 0.7410 0.8500 0.3250 0.0980 0.9290 0.6940 0.1250 0.4940 0.1840 0.5560 0.4660 0.6740 0.1880 0.3010 0.7450 0.9330 0.6350 0.0780 0.1840 </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_02.png"/> <p>This default color order is designed to distinguish distinct lines by well separated colors. It does a good job at this.</p><h4>Parula<a></a></h4><p>But I often want to emphasize the interrelations among related lines. So, I set the color order to one obtained from our colormaps. <tt>Parula</tt> is my first choice.</p><pre> set(gca,<span>'colororder'</span>,parula(7)) rgb = get(gca,<span>'colororder'</span>) show_colors(rgb) </pre><pre>rgb = 0.2422 0.1504 0.6603 0.2780 0.3556 0.9777 0.1540 0.5902 0.9218 0.0704 0.7457 0.7258 0.5044 0.7993 0.3480 0.9871 0.7348 0.2438 0.9769 0.9839 0.0805 </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_03.png"/> <p>I am about to use this function.</p><pre> type <span>cplot.m</span> </pre><pre>function cplot(Y,cmap) close [m,n] = size(Y); a = axes('colororder',cmap(m)); line(a,1:n,Y,'linewidth',2) box on end </pre><p>Here is my first example.</p><pre> n = 19; cplot(magic(n),@parula) title(sprintf(<span>'magic(%d)'</span>,n)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_04.png"/> <p>By the way, you are seeing three kinds of magic squares -- when the order <tt>n</tt> is odd, when <tt>n</tt> is divisible by four, and when <tt>n</tt> is even but not divisable by four.</p><h4>Jet<a></a></h4><p>Let's not forget our former best friend, <tt>jet</tt>.</p><pre> show_colors(jet(7)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_05.png"/> <pre> n = 20; cplot(magic(n),@jet) title(sprintf(<span>'magic(%d)'</span>,n)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_06.png"/> <h4>Copper<a></a></h4><p>I am especially fond of the <tt>copper</tt> colormap in these situations.</p><pre> show_colors(copper(7)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_07.png"/> <p>Singly even magic squares are the most complicated.</p><pre> n = 18; cplot(magic(n),@copper) title(sprintf(<span>'magic(%d)'</span>,n)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_08.png"/> <h4>Peaks<a></a></h4><p>We ordinarily use our <tt>peaks</tt> function to demo <tt>surf</tt> or <tt>contour</tt> plots, but it is also useful to view <tt>peaks</tt> as a series of lines.</p><pre> n = 40; cplot(peaks(n)',@parula) title(sprintf(<span>'peaks(%d)'</span>,n)) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_09.png"/> <h4>Kuramoto<a></a></h4><p>I am using colored line plots in my blog posts about <a href="https://blogs.mathworks.com/cleve/2019/10/30/stability-of-kuramoto-oscillators/">Kuramoto oscillators</a>.</p><pre> load <span>history</span> <span>H</span> kuramoto_plots(H) </pre><img src="http://blogs.mathworks.com/cleve/files/cplot_blog_10.png"/> <h4>Clean up<a></a></h4><pre> set(gcf,<span>'position'</span>,<span>'factory'</span>) close </pre><p><br/><a><span>Get the MATLAB code </span></a><br/><br/> Published with MATLAB® R2018b<br/></p></div> </div> </div> <div> <div> <div> <strong>473</strong> views (last 30 days) | <button><span></span></button> | <button></button> </div> </div> </div> <div> <div> <div> <dl><dt><strong>Category:</strong> </dt><dd><a href="https://blogs.mathworks.com/cleve/category/color/">Color,</a></dd> <dd><a href="https://blogs.mathworks.com/cleve/category/graphics/">Graphics,</a></dd> <dd><a href="https://blogs.mathworks.com/cleve/category/magic-squares/">Magic Squares</a></dd> </dl> </div> <div> <div><ul> <li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/"><img src="https://blogs.mathworks.com/cleve/wp-content/themes/mathworks_1.0/images/btn_print.png"/></a> </li> <li><a href="https://blogs.mathworks.com/cleve/2019/11/04/color-order-for-line-plots/"> <img src="https://blogs.mathworks.com/cleve/wp-content/themes/mathworks_1.0/images/btn_send.png"/> </a> </li> <li><a></a></li> <li><a></a></li> <li> <a></a> </li> </ul></div> </div> </div> </div> <div> <nav> <ul> <li><a href="https://blogs.mathworks.com/cleve/2019/10/30/stability-of-kuramoto-oscillators/"><span>< Stability of Kuramoto Oscillators </span><span> < Previous</span></a></li> </ul> </nav> </div> <div> <link href="https://blogs.mathworks.com/wp-content/plugins/mw_blogs_related_content_plugin/css/lightslider.css"/> <link href="https://blogs.mathworks.com/wp-content/plugins/mw_blogs_related_content_plugin/css/related.css"/> <div> <h3>See Also</h3> <ul> <li> <div> <div> <div> <div> <a href="https://blogs.mathworks.com/cleve/2013/09/30/iterated-powers-fractal/?s_tid=blogs_rc_1"> <img src="https://blogs.mathworks.com/images/cleve/view1.png"/> </a> </div> <p>Blogs</p> </div> </div> </div> </li> <li> <div> <div> <div> <div> <a href="https://blogs.mathworks.com/loren/2014/11/05/matlab-r2014b-graphics-part-3-compatibility-considerations-in-the-new-graphics-system/?s_tid=blogs_rc_2"> <img src="https://blogs.mathworks.com/images/loren/2014/colormap.png"/> </a> </div> <p>Blogs</p> </div> </div> </div> </li> <li> <div> <div> <div> <div> <a href="https://blogs.mathworks.com/cleve/2017/02/20/hypercubes-and-graphs/?s_tid=blogs_rc_3"> <img src="https://blogs.mathworks.com/cleve/files/graphs_blog_01.png"/> </a> </div> <p>Blogs</p> </div> </div> </div> </li> <li> <div> <div> <div> <div> <a href="https://www.mathworks.com/matlabcentral/fileexchange/45208-colorbrewer-attractive-and-distinctive-colormaps?s_tid=blogs_rc_4"> <img src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/e5a6dcde-4a80-11e4-9553-005056977bd0/7aba0af0-710d-4c57-8f8c-e0d87beef1e9/images/screenshot.png"/> </a> </div> <p>File Exchange</p> </div> </div> </div> </li> <li> <div> <div> <div> <div> <a href="https://www.mathworks.com/matlabcentral/fileexchange/62729-matplotlib-perceptually-uniform-colormaps?s_tid=blogs_rc_5"> <img src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/f516cde2-db42-44f1-83a9-8d0c700cd941/7b2dfbbf-1f02-4b23-bcaf-0d274b013d03/images/screenshot.png"/> </a> </div> <p>File Exchange</p> </div> </div> </div> </li> <li> <div> <div> <div> <div> <a href="https://www.mathworks.com/matlabcentral/fileexchange/42673-beautiful-and-distinguishable-line-colors-colormap?s_tid=blogs_rc_6"> <img src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/42673/versions/6/screenshot.png"/> </a> </div> <p>File Exchange</p> </div> </div> </div> </li> </ul> </div> </div> <div> <p> </p> </div> [url=http://feedproxy.google.com/~r/mathworks/moler/~3/5ohY53d97DY/]more...[/url] |
所有时间均为北京时间。现在的时间是 23:28。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.