{"id":2522,"date":"2010-01-22T11:56:14","date_gmt":"2010-01-22T11:56:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/22\/labeledgesubplots\/"},"modified":"2017-01-06T21:26:54","modified_gmt":"2017-01-07T02:26:54","slug":"labeledgesubplots","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/22\/labeledgesubplots\/","title":{"rendered":"labelEdgeSubPlots"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021\">Bob<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots\">labelEdgeSubPlots<\/a> by Rob Campbell.\r\n      <\/p>\r\n   <\/introduction>\r\n   <div>\r\n      <ul>\r\n         <li>Do you use <tt><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/subplot.html\">subplot<\/a><\/tt> a lot in your MATLAB analyses?\r\n         <\/li>\r\n         <li>Do your subplots share the same X and Y range?<\/li>\r\n         <li>Do you like to label axes <i>only<\/i> along the left and bottom?\r\n         <\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>You could write code to do that yourself. It's not difficult.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #0000FF\">for<\/span> k=1:9\r\n  ax(k) = subplot(3,3,k);\r\n  plot(1:10)\r\n  <span style=\"color: #0000FF\">if<\/span> mod(k,3)==1 <span style=\"color: #228B22\">%left<\/span>\r\n    ylabel <span style=\"color: #A020F0\">Output<\/span>\r\n  <span style=\"color: #0000FF\">end<\/span>\r\n  <span style=\"color: #0000FF\">if<\/span> k&gt;6 <span style=\"color: #228B22\">%bottom<\/span>\r\n    xlabel <span style=\"color: #A020F0\">Input<\/span>\r\n  <span style=\"color: #0000FF\">end<\/span>\r\n<span style=\"color: #0000FF\">end<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/labeledges_01.png\"> <p>Or you could just use <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots\">labelEdgeSubPlots<\/a>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #0000FF\">for<\/span> k=1:9\r\n  ax(k) = subplot(3,3,k);\r\n  plot(1:10)\r\n<span style=\"color: #0000FF\">end<\/span>\r\nh = labelEdgeSubPlots(<span style=\"color: #A020F0\">'Input'<\/span>,<span style=\"color: #A020F0\">'Output'<\/span>)<\/pre><pre style=\"font-style:oblique\">h = \r\n    xlabels: [220.01 216.01 212.01]\r\n    ylabels: [213.01 201.01 187.01]\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/labeledges_02.png\"> <p>Notice it returns <tt><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/axes.html\">axes<\/a><\/tt> handles. That helps customize your plots as much as you wish.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">%make all axes labels italic<\/span>\r\nset([h.ylabels h.xlabels],<span style=\"color: #A020F0\">'FontAngle'<\/span>,<span style=\"color: #A020F0\">'italic'<\/span>)\r\n\r\n<span style=\"color: #228B22\">%draw special attention to center plot (12pt bold)<\/span>\r\nset([ax(5) h.xlabels(2) h.ylabels(2)],<span style=\"color: #A020F0\">'FontWeight'<\/span>,<span style=\"color: #A020F0\">'bold'<\/span>,<span style=\"color: #A020F0\">'FontSize'<\/span>,12)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/labeledges_03.png\"> <p>Another nifty feature involves how <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots\">labelEdgeSubPlots<\/a> handles sparse subplots as shown in Rob's example screen shot.\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2522#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_78edc268332c40028cb124c4380d56ab() {\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='78edc268332c40028cb124c4380d56ab ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 78edc268332c40028cb124c4380d56ab';\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 = 'Robert Bemis';\r\n        copyright = 'Copyright 2010 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_78edc268332c40028cb124c4380d56ab()\"><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; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n78edc268332c40028cb124c4380d56ab ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021 Bob>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots labelEdgeSubPlots> \r\n% by Rob Campbell.\r\n%%\r\n% * Do you use \r\n% |<https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/subplot.html subplot>|\r\n% a lot in your MATLAB analyses? \r\n% * Do your subplots share the same X and Y range? \r\n% * Do you like to label axes _only_ along the left and bottom?\r\n%%\r\n% You could write code to do that yourself. It's not difficult.\r\nfor k=1:9\r\n  ax(k) = subplot(3,3,k);\r\n  plot(1:10)\r\n  if mod(k,3)==1 %left\r\n    ylabel Output\r\n  end\r\n  if k>6 %bottom\r\n    xlabel Input\r\n  end\r\nend\r\n%%\r\n% Or you could just use \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots labelEdgeSubPlots>.\r\nfor k=1:9\r\n  ax(k) = subplot(3,3,k);\r\n  plot(1:10)\r\nend\r\nh = labelEdgeSubPlots('Input','Output')\r\n%%\r\n% Notice it returns \r\n% |<https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/ref\/axes.html axes>|\r\n% handles. That helps customize your plots as much as you wish.\r\n\r\n%make all axes labels italic\r\nset([h.ylabels h.xlabels],'FontAngle','italic')\r\n\r\n%draw special attention to center plot (12pt bold)\r\nset([ax(5) h.xlabels(2) h.ylabels(2)],'FontWeight','bold','FontSize',12)\r\n%%\r\n% Another nifty feature involves how \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26332-labeledgesubplots labelEdgeSubPlots>\r\n% handles sparse subplots as shown in Rob's \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/26332\/3\/labelEdgeSubPlots.png example screen shot>.\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2522#respond Comments?>\r\n\r\n##### SOURCE END ##### 78edc268332c40028cb124c4380d56ab\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Bob's pick this week is labelEdgeSubPlots by Rob Campbell.\r\n      \r\n   \r\n   \r\n      \r\n         Do you use subplot a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/22\/labeledgesubplots\/\">read more >><\/a><\/p>","protected":false},"author":46,"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\/2522"}],"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\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2522"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2522\/revisions"}],"predecessor-version":[{"id":8331,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2522\/revisions\/8331"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}