{"id":4114,"date":"2012-12-21T09:00:49","date_gmt":"2012-12-21T14:00:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4114"},"modified":"2019-10-21T12:55:42","modified_gmt":"2019-10-21T16:55:42","slug":"figure-margins-subplot-spacings-and-more","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2012\/12\/21\/figure-margins-subplot-spacings-and-more\/","title":{"rendered":"Figure margins, subplot spacings, and more&#8230;"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n<p style=\"background-color:#87CEEB;text-align:center;vertical-align:middle;\"><span style=\"font-weight:bold;\">NOTE: <\/span><span>Functionality similar to this File Exchange entry was added to MATLAB in R2019b.<\/span><br><span>See the <\/span><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2019b\/matlab\/ref\/tiledlayout.html\"><span>TiledLayout<\/span><\/a><span> and this <\/span><a href=\"https:\/\/blogs.mathworks.com\/pick\/2019\/09\/13\/tiled-layout\/\"><span>Pick of the Week Blog Post<\/span><\/a><span> that introduces it.<\/span><\/p> \r\n      \r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt\"><tt>tightfig<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/34660\">Richard Crozier<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Subplot and its large margins<\/a><\/li>\r\n         <li><a href=\"#2\">tightfig<\/a><\/li>\r\n         <li><a href=\"#4\">Review of the other entries<\/a><\/li>\r\n         <li><a href=\"#9\">Conclusion<\/a><\/li>\r\n         <li><a href=\"#10\">Comments<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Subplot and its large margins<a name=\"1\"><\/a><\/h3>\r\n   <p>In response to my last <a href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/12\/07\/tell-us-what-you-want-to-read-about\/\">post<\/a>, Richard Johnson <a href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/12\/07\/tell-us-what-you-want-to-read-about\/#comment-16825\">asked<\/a> whether we could write posts that compared similar entries, for instance \"arrows\" and \"waitbars\". Just for kicks, I searched\r\n      the File Exchange for entries with the tag <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/index?term=tag%3A%22waitbar%22\">\"waitbar\"<\/a>, and it returned close to 70. One of these days, I may get around to testing all of them, but not right now. Hey, even the\r\n      fact that there are a lot of \"waitbar\" entries has already been <a href=\"https:\/\/blogs.mathworks.com\/community\/2012\/08\/13\/wait-bars-and-beyond-call-me-when-youre-done\/\">blogged<\/a> about.\r\n   <\/p>\r\n   <p>With that daunting task of reviewing 70 files weighing heavily in my head, I came across Richard Crozier's <tt>tightfig<\/tt>. It caught my eye, because I like anything related to visualization, and people have asked about (how to get rid of) large\r\n      margins in subplots. Then, I remembered seeing something similar before. In fact, Brett <a href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/06\/08\/customize-the-spacing-of-subplots-2\/\">picked<\/a> <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27991-tight-subplot-nh--nw--gap--marg-h--marg-w-\">\"tight subplot\"<\/a> earlier this year. Nice! Maybe I could compare these two files.\r\n   <\/p>\r\n   <p>After reading through the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt#comments\">comments<\/a> for <tt>tightfig<\/tt>, one of the commenters mentioned 5 other similar entries (<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30884-controllable-tight-subplot\">subplot_tight<\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35464-spaceplots\">spaceplots<\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/9694-an-improved-subplot-function\">subplot1<\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/34594-subplotplus---enhanced-layout-matlab-subplot-function\">subplotplus<\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27991-tight-subplot-nh--nw--gap--marg-h--marg-w-\">tight_subplot<\/a>). Sounds good! That's a more reasonable number of entries to review. Luckily, Richard has already done some reviews himself,\r\n      but I'll try to add some of mine below.\r\n   <\/p>\r\n   <h3>tightfig<a name=\"2\"><\/a><\/h3>\r\n   <p>The first thing I want to mention is that <tt>tightfig<\/tt> has a different purpose than the other entries. The description on the entry page explains the purpose very well: \"Alters\r\n      a figure so that it has the minimum size necessary to enclose all axes in the figure without excess space around them.\" Note\r\n      that this is about making the outer bounds of the figure <i>tight<\/i>. Its intention is not to modify any of the spacings between the axes, which is the primary purpose of the other entries.\r\n      I'll say more on this later.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure(<span style=\"color: #A020F0\">'Color'<\/span>, [.8 .8 .8]);\r\n\r\nsubplot(2,2,1);\r\nsurf(peaks); shading <span style=\"color: #A020F0\">interp<\/span>\r\ntitle(<span style=\"color: #A020F0\">'Peaks'<\/span>);\r\nylabel(colorbar, <span style=\"color: #A020F0\">'Color Scale'<\/span>);\r\n\r\nsubplot(2,2,2);\r\nplot(rand(10,3));\r\nxlabel(<span style=\"color: #A020F0\">'time'<\/span>);\r\nylabel(<span style=\"color: #A020F0\">'money'<\/span>);\r\n\r\nsubplot(2,2,3);\r\nimshow(<span style=\"color: #A020F0\">'peppers.png'<\/span>);\r\n\r\nsubplot(2,2,4);\r\nsurf(membrane(1));\r\nxlabel(<span style=\"color: #A020F0\">'x label'<\/span>);\r\nylabel(<span style=\"color: #A020F0\">'y label'<\/span>);\r\nzlabel(<span style=\"color: #A020F0\">'z label'<\/span>);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_01.png\"> <p><p><\/p><tt>tightfig<\/tt> is extremely simple to use. You just call it after creating your plots, and it applies to the current figure. That's one\r\n      of my favorite things about this entry.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">tightfig;<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_02.png\"> <h3>Review of the other entries<a name=\"4\"><\/a><\/h3>\r\n   <p>Before looking into the other entries, I'd like to point out that the use case for <tt>tightfig<\/tt> is quite different from that of the others. One is for tightening the figure boundary, and the others are for controlling\/tightening\r\n      the axes boundaries. So it may not be an apples-to-apples comparison. Nonetheless, here I go. Oh, and try not to get confused\r\n      with all the names. :)\r\n   <\/p>\r\n   <p><b>subplot_tight<\/b><\/p>\r\n   <p>I find <tt>subplot_tight<\/tt> to be the easiest to use, since it has a syntax that is closest to the MATLAB function <tt>subplot<\/tt>. Not surprisingly, it is a wrapper around <tt>subplot<\/tt>, with an added option to specify the spacing between an axes and its neighbors. Because it's a wrapper, you can make use\r\n      of the vector input syntax for the 3rd parameter (see below). The author also supplies a demo script to recreate his screenshot.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure;\r\nsubplot_tight(2, 2, 1, .1);\r\nsubplot_tight(2, 2, 2, .05);\r\nsubplot_tight(2, 2, [3 4], .05);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_03.png\"> <p><\/p><p><b>tight_subplot<\/b> and <b>subplot1<\/b><\/p>\r\n   <p><tt>tight_subplot<\/tt> and <tt>subplot1<\/tt> are quite similar. They both allow you to lay out a grid of subplots with arbitrary spacings and margins. <tt>tight_subplot<\/tt> is compact with just those parameters, i.e. spacing and margin, while <tt>subplot1<\/tt> lets you control other axes properties, such as tick labels, label font size, and axes scale. I like that it gives me the\r\n      ability to have the tick labels only displayed on the outside with <tt>subplot1<\/tt> (see example below).\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% tight_subplot<\/span>\r\n\r\nfigure;\r\nhA = tight_subplot(3, 2, [.01 .03], [.1 .01], [.01 .01]);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_04.png\"><p><\/p> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% subplot1<\/span>\r\n\r\nfigure;\r\nsubplot1(3, 2, <span style=\"color: #A020F0\">'Gap'<\/span>, [.01 .03], <span style=\"color: #A020F0\">'XTickL'<\/span>, <span style=\"color: #A020F0\">'Margin'<\/span>, <span style=\"color: #A020F0\">'YTickL'<\/span>, <span style=\"color: #A020F0\">'Margin'<\/span>);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_05.png\"> <p><\/p><p><b>spaceplots<\/b><\/p>\r\n   <p><tt>spaceplots<\/tt> works like <tt>tightfig<\/tt>, in that you create your figure first with subplots, then call <tt>spaceplots<\/tt> to adjust the spacings and margins. This function, unlike <tt>tightfig<\/tt>, will allow you to adjust the spacings between axes, not just the outside margin. The part that I like most is that it will\r\n      work with irregular-grid subplots (see example below). However, there's a caveat that it only works on axes created using\r\n      <tt>subplot<\/tt>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure;\r\nsubplot(2, 2, [1 2]); plot(rand(10, 3));\r\nsubplot(2, 2, 3); surf(peaks); title(<span style=\"color: #A020F0\">'Peaks'<\/span>)\r\nsubplot(2, 2, 4); contourf(peaks);\r\n\r\n<span style=\"color: #228B22\">% 0 margin, 0.02 (normalized) spacing<\/span>\r\nspaceplots([0 0 0 0], [.02 .02]);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_06.png\"> <p><\/p><p><b>subplotplus<\/b><\/p>\r\n   <p><tt>subplotplus<\/tt> is the king of custom subplots. It comes with a price of somewhat cryptic syntax, but once you understand it (with the help\r\n      of an example script), it can let you custom layout your subplots in any configuration you like. It even includes the ability\r\n      to \"glue\" axes together so that they have a common axis.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">cell71={{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]}};\r\ncell41={{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]};{[<span style=\"color: #A020F0\">'-g'<\/span>]}};\r\n\r\nfigure;\r\nC = {{{{[]},{[]}};cell41},cell71};\r\n[h,labelfontsize] = subplotplus(C);<\/pre><p><\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_tightfig\/potw_tightfig_07.png\"> <h3>Conclusion<a name=\"9\"><\/a><\/h3>\r\n   <p>So what have I concluded from this review? There are multiple solutions to a problem! They all have unique ways of tackling\r\n      the problem, and some solve a slightly different problem than others. Overall, I prefer the \"post-processing\" type functions,\r\n      <tt>tightfig<\/tt> and <tt>spaceplots<\/tt>. I tend to do my exploratory plotting in a rough state, and once I have a plot I like, then I start making things look nicer.\r\n      But of course, with an interactive tool like MATLAB, even the \"pre-processing\" type functions can be introduced at a later\r\n      step.\r\n   <\/p>\r\n   <h3>Comments<a name=\"10\"><\/a><\/h3>\r\n   <p>I'm interested to hear from anyone who has looked at all\/any\/one of these entries. Give us your feedback <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4114#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_0f922a92bb4f4246947944602ae22064() {\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='0f922a92bb4f4246947944602ae22064 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 0f922a92bb4f4246947944602ae22064';\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 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<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');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_0f922a92bb4f4246947944602ae22064()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p>\r\n<\/div>\r\n<!--\r\n0f922a92bb4f4246947944602ae22064 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt |tightfig|> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/34660\r\n% Richard Crozier>.\r\n\r\n%% Subplot and its large margins\r\n% In response to my last\r\n% <https:\/\/blogs.mathworks.com\/pick\/2012\/12\/07\/tell-us-what-you-want-to-read-about\/\r\n% post>, Richard Johnson\r\n% <https:\/\/blogs.mathworks.com\/pick\/2012\/12\/07\/tell-us-what-you-want-to-read-about\/#comment-16825\r\n% asked> whether we could write posts that compared similar entries, for\r\n% instance \"arrows\" and \"waitbars\". Just for kicks, I searched the File\r\n% Exchange for entries with the tag\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/index?term=tag%3A%22waitbar%22\r\n% \"waitbar\">, and it returned close to 70. One of these days, I may get\r\n% around to testing all of them, but not right now. Hey, even the fact that\r\n% there are a lot of \"waitbar\" entries has already been\r\n% <https:\/\/blogs.mathworks.com\/community\/2012\/08\/13\/wait-bars-and-beyond-call-me-when-youre-done\/\r\n% blogged> about.\r\n%\r\n% With that daunting task of reviewing 70 files weighing heavily in my\r\n% head, I came across Richard Crozier's |tightfig|. It caught my eye,\r\n% because I like anything related to visualization, and people have asked\r\n% about (how to get rid of) large margins in subplots. Then, I remembered\r\n% seeing something similar before. In fact, Brett\r\n% <https:\/\/blogs.mathworks.com\/pick\/2012\/06\/08\/customize-the-spacing-of-subplots-2\/\r\n% picked> <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27991-tight-subplot-nh--nw--gap--marg-h--marg-w- \"tight\r\n% subplot\"> earlier this year. Nice! Maybe I could compare these two files.\r\n%\r\n% After reading through the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/340-saveppt#comments\r\n% comments> for |tightfig|, one of the commenters mentioned 5 other similar\r\n% entries (<https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/30884-controllable-tight-subplot\r\n% subplot_tight>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/35464-spaceplots spaceplots>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/9694-an-improved-subplot-function subplot1>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/34594-subplotplus---enhanced-layout-matlab-subplot-function subplotplus>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27991-tight-subplot-nh--nw--gap--marg-h--marg-w-\r\n% tight_subplot>). Sounds good! That's a more reasonable number of entries\r\n% to review. Luckily, Richard has already done some reviews himself, but\r\n% I'll try to add some of mine below.\r\n\r\n%% tightfig\r\n% The first thing I want to mention is that |tightfig| has a different\r\n% purpose than the other entries. The description on the entry page\r\n% explains the purpose very well: \"Alters a figure so that it has the\r\n% minimum size necessary to enclose all axes in the figure without excess\r\n% space around them.\" Note that this is about making the outer bounds of\r\n% the figure _tight_. Its intention is not to modify any of the spacings\r\n% between the axes, which is the primary purpose of the other entries. I'll\r\n% say more on this later.\r\n\r\nfigure('Color', [.8 .8 .8]);\r\n\r\nsubplot(2,2,1);\r\nsurf(peaks); shading interp\r\ntitle('Peaks');\r\nylabel(colorbar, 'Color Scale');\r\n\r\nsubplot(2,2,2);\r\nplot(rand(10,3));\r\nxlabel('time');\r\nylabel('money');\r\n\r\nsubplot(2,2,3);\r\nimshow('peppers.png');\r\n\r\nsubplot(2,2,4);\r\nsurf(membrane(1));\r\nxlabel('x label');\r\nylabel('y label');\r\nzlabel('z label');\r\n\r\n%%\r\n% |tightfig| is extremely simple to use. You just call it after creating\r\n% your plots, and it applies to the current figure. That's one of my\r\n% favorite things about this entry.\r\n\r\ntightfig;\r\n\r\n%% Review of the other entries\r\n% Before looking into the other entries, I'd like to point out that the use\r\n% case for |tightfig| is quite different from that of the others. One is\r\n% for tightening the figure boundary, and the others are for\r\n% controlling\/tightening the axes boundaries. So it may not be an\r\n% apples-to-apples comparison. Nonetheless, here I go. Oh, and try not to\r\n% get confused with all the names. :)\r\n%\r\n% *subplot_tight*\r\n%\r\n% I find |subplot_tight| to be the easiest to use, since it has a syntax\r\n% that is closest to the MATLAB function |subplot|. Not surprisingly, it is\r\n% a wrapper around |subplot|, with an added option to specify the spacing\r\n% between an axes and its neighbors. Because it's a wrapper, you\r\n% can make use of the vector input syntax for the 3rd parameter (see\r\n% below). The author also supplies a demo script to recreate his\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/30884\/3\/subplot_tight.PNG\r\n% screenshot>.\r\n\r\nfigure;\r\nsubplot_tight(2, 2, 1, .1);\r\nsubplot_tight(2, 2, 2, .05);\r\nsubplot_tight(2, 2, [3 4], .05);\r\n\r\n%%\r\n% *tight_subplot* and *subplot1*\r\n%\r\n% |tight_subplot| and |subplot1| are quite similar. They both allow you to\r\n% lay out a grid of subplots with arbitrary spacings and margins.\r\n% |tight_subplot| is compact with just those parameters, i.e. spacing and\r\n% margin, while |subplot1| lets you control other axes properties, such as\r\n% tick labels, label font size, and axes scale. I like that it gives me the\r\n% ability to have the tick labels only displayed on the outside with\r\n% |subplot1| (see example below).\r\n\r\n% tight_subplot\r\n\r\nfigure;\r\nhA = tight_subplot(3, 2, [.01 .03], [.1 .01], [.01 .01]);\r\n\r\n%%\r\n\r\n% subplot1\r\n\r\nfigure;\r\nsubplot1(3, 2, 'Gap', [.01 .03], 'XTickL', 'Margin', 'YTickL', 'Margin');\r\n\r\n%%\r\n% *spaceplots*\r\n%\r\n% |spaceplots| works like |tightfig|, in that you create your figure first\r\n% with subplots, then call |spaceplots| to adjust the spacings and margins.\r\n% This function, unlike |tightfig|, will allow you to adjust the spacings\r\n% between axes, not just the outside margin. The part that I like most is\r\n% that it will work with irregular-grid subplots (see example below).\r\n% However, there's a caveat that it only works on axes created using\r\n% |subplot|.\r\n\r\nfigure;\r\nsubplot(2, 2, [1 2]); plot(rand(10, 3));\r\nsubplot(2, 2, 3); surf(peaks); title('Peaks')\r\nsubplot(2, 2, 4); contourf(peaks);\r\n\r\n% 0 margin, 0.02 (normalized) spacing\r\nspaceplots([0 0 0 0], [.02 .02]);\r\n\r\n%%\r\n% *subplotplus*\r\n% \r\n% |subplotplus| is the king of custom subplots. It comes with a price of\r\n% somewhat cryptic syntax, but once you understand it (with the help of an\r\n% example script), it can let you custom layout your subplots in any\r\n% configuration you like. It even includes the ability to \"glue\" axes\r\n% together so that they have a common axis. \r\n\r\ncell71={{['-g']};{['-g']};{['-g']};{['-g']};{['-g']};{['-g']};{['-g']}};\r\ncell41={{['-g']};{['-g']};{['-g']};{['-g']}};\r\n\r\nfigure;\r\nC = {{{{[]},{[]}};cell41},cell71};\r\n[h,labelfontsize] = subplotplus(C);\r\n\r\n%% Conclusion\r\n% So what have I concluded from this review? There are multiple solutions\r\n% to a problem! They all have unique ways of tackling the problem, and some\r\n% solve a slightly different problem than others. Overall, I prefer the\r\n% \"post-processing\" type functions, |tightfig| and |spaceplots|. I tend to\r\n% do my exploratory plotting in a rough state, and once I have a plot I\r\n% like, then I start making things look nicer. But of course, with an\r\n% interactive tool like MATLAB, even the \"pre-processing\" type functions\r\n% can be introduced at a later step.\r\n\r\n%% Comments\r\n% I'm interested to hear from anyone who has looked at all\/any\/one of these\r\n% entries. Give us your feedback\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4114#respond here>.\r\n\r\n##### SOURCE END ##### 0f922a92bb4f4246947944602ae22064\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\nNOTE: Functionality similar to this File Exchange entry was added to MATLAB in R2019b.See the TiledLayout and this Pick of the Week Blog Post that introduces it. \r\n      \r\n   \r\n      Jiro's pick... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/12\/21\/figure-margins-subplot-spacings-and-more\/\">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\/4114"}],"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=4114"}],"version-history":[{"count":17,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4114\/revisions"}],"predecessor-version":[{"id":11122,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4114\/revisions\/11122"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}