{"id":10994,"date":"2019-09-13T09:09:33","date_gmt":"2019-09-13T13:09:33","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=10994"},"modified":"2019-09-13T09:09:33","modified_gmt":"2019-09-13T13:09:33","slug":"tiled-layout","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2019\/09\/13\/tiled-layout\/","title":{"rendered":"Tiled Layout"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n   <introduction><\/p>\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/tiledlayout.html\"><tt>tiledlayout<\/tt><\/a> by MathWorks&#8217;s development team.\n      <\/p>\n<p>R2019b shipped on September 12th and is now available for download!<\/p>\n<p>Check the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/release-notes.html\">Release Notes<\/a> for all of the updates.\n      <\/p>\n<p>   <\/introduction><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#1\">subplot&#8217;s Replacement<\/a><\/li>\n<li><a href=\"#2\">Minimize Whitespace<\/a><\/li>\n<li><a href=\"#4\">Reflow<\/a><\/li>\n<li><a href=\"#5\">Stacked Plot<\/a><\/li>\n<li><a href=\"#6\">Comments<\/a><\/li>\n<\/ul><\/div>\n<h3>subplot&#8217;s Replacement<a name=\"1\"><\/a><\/h3>\n<p>I imagine most of you have probably used <tt>subplot<\/tt> at some point.\n   <\/p>\n<p>Subplot alternatives or extensions are very popular on the File Exchange. In fact, I think it may be the most popular topic of contributions to the FEX.  A quick search reveals many of the pains associated with subplots:\n   <\/p>\n<div>\n<ul>\n<li>Too much spacing between them<\/li>\n<li>Too much padding on the edges<\/li>\n<li>Difficulty in arranging the axes based on figure size<\/li>\n<li>Scaling issues<\/li>\n<\/ul><\/div>\n<p>Enter R2019b, and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/tiledlayout.html\"><tt>tiledlayout<\/tt><\/a>.  Tiled layouts give us all of the above.  Let&#8217;s look at two examples: minimizing whitespace, and resizing\/rescaling.\n   <\/p>\n<h3>Minimize Whitespace<a name=\"2\"><\/a><\/h3>\n<p>Create a <tt>tiledlayout<\/tt>, and use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/nexttile.html\"><tt>nexttile<\/tt><\/a> to traverse it.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure\r\ntlt = tiledlayout(2, 2);\r\nnexttile\r\nplot(sin(1:100));\r\n\r\nnexttile\r\nsurf(peaks)\r\n\r\nnexttile([1 2]) <span style=\"color: #228B22\">% Spanned<\/span>\r\nribbon(sin(1:100), cos(1:100))<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainTiledLayout_01.png\"> <\/p>\n<p>And let&#8217;s get rid of that whitespace!<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">tlt.Padding = <span style=\"color: #A020F0\">\"none\"<\/span>;\r\ntlt.TileSpacing = <span style=\"color: #A020F0\">\"none\"<\/span>;<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainTiledLayout_02.png\"> <\/p>\n<h3>Reflow<a name=\"4\"><\/a><\/h3>\n<p>The above example used a fixed grid of 2&#215;2 like you might use with subplot.  There&#8217;s also an option to &#8220;flow&#8221; which will rearrange the plots based on the figure size.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure\r\ntlt = tiledlayout(<span style=\"color: #A020F0\">\"flow\"<\/span>);\r\nnexttile\r\nplot(sin(1:100));\r\n\r\nnexttile\r\nsurf(peaks)\r\n\r\nnexttile\r\nribbon(sin(1:100), cos(1:100))<\/pre>\n<p><embed src=\"https:\/\/blogs.mathworks.com\/pick\/files\/tileflow.mp4\" height=\"600\" width=\"800\"><\/p>\n<h3>Stacked Plot<a name=\"5\"><\/a><\/h3>\n<p>Additionally, if you&#8217;re using sub plots or tiles to show many variables against the same x-axis, you may want to look at <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/stackedplot.html\"><tt>stackedplot<\/tt><\/a> which does this for you.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure\r\nstackedplot((1:100).', rand(100, 4));<\/pre>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainTiledLayout_07.png\"> <\/p>\n<h3>Comments<a name=\"6\"><\/a><\/h3>\n<p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=10994#respond\">here<\/a>.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_c53040880a054018a49b47313085f726() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='c53040880a054018a49b47313085f726 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' c53040880a054018a49b47313085f726';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sean de Wolski';\n        copyright = 'Copyright 2019 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\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>\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_c53040880a054018a49b47313085f726()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n            the MATLAB code<br \/>\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2019b<\/p>\n<\/div>\n<p><!--\nc53040880a054018a49b47313085f726 ##### SOURCE BEGIN #####\n%% Tiled Layout\n%\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s\n% pick this week is\n% <https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/tiledlayout.html\n% |tiledlayout|> by MathWorks's development team.\n% \n%\n% R2019b shipped on September 12th and is now available for download!\n%\n% Check the\n% <https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/release-notes.html\n% Release Notes> for all of the updates.\n\n%% |subplot|'s Replacement\n%\n% I imagine most of you have probably used |subplot| at some point.\n%\n% Subplot alternatives or extensions are very popular on the File Exchange.\n% In fact, I think it may be the most popular topic of contributions to the\n% FEX.  A quick search reveals many of the pains associated with subplots:\n%\n% * Too much spacing between them\n% * Too much padding on the edges\n% * Difficulty in arranging the axes based on figure size\n% * Scaling issues\n%\n% Enter R2019b, and\n% <https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/tiledlayout.html\n% |tiledlayout|>.  Tiled layouts give us all of the above.  Let's look at\n% two examples: minimizing whitespace, and resizing\/rescaling.\n\n%% Minimize Whitespace\n% Create a |tiledlayout|, and use\n% <https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/nexttile.html\n% |nexttile|> to traverse it.\n\nfigure\ntlt = tiledlayout(2, 2);\nnexttile\nplot(sin(1:100));\n\nnexttile\nsurf(peaks)\n\nnexttile([1 2]) % Spanned\nribbon(sin(1:100), cos(1:100))\n\n%%\n% And let's get rid of that whitespace!\ntlt.Padding = \"none\";\ntlt.TileSpacing = \"none\";\n\n%% Reflow\n% The above example used a fixed grid of 2x2 like you might use with\n% subplot.  There's also an option to \"flow\" which will rearrange the plots\n% based on the figure size.\n\nfigure\ntlt = tiledlayout(\"flow\");\nnexttile\nplot(sin(1:100));\n\nnexttile\nsurf(peaks)\n\nnexttile\nribbon(sin(1:100), cos(1:100))\n\n%% Stacked Plot\n% Additionally, if you're using sub plots or tiles to show many variables\n% against the same x-axis, you may want to look at\n% <https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/stackedplot.html\n% |stackedplot|> which does this for you.\n\nfigure\nstackedplot((1:100).', rand(100, 4));\n\n%% Comments\n% \n% Give it a try and let us know what you think\n% <http:\/\/blogs.mathworks.com\/pick\/?p=10994#respond here>.\n \n\n##### SOURCE END ##### c53040880a054018a49b47313085f726\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainTiledLayout_01.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Sean&#8216;s pick this week is tiledlayout by MathWorks&#8217;s development team.<\/p>\n<p>R2019b shipped on September 12th and is now available for download!<br \/>\nCheck the Release Notes for all of&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2019\/09\/13\/tiled-layout\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"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\/10994"}],"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\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=10994"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10994\/revisions"}],"predecessor-version":[{"id":11022,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10994\/revisions\/11022"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=10994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=10994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=10994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}