{"id":16037,"date":"2022-07-01T09:00:56","date_gmt":"2022-07-01T13:00:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=16037"},"modified":"2022-07-01T20:55:37","modified_gmt":"2022-07-02T00:55:37","slug":"get-your-subplots-the-way-you-want-it-with-subplothelper","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2022\/07\/01\/get-your-subplots-the-way-you-want-it-with-subplothelper\/","title":{"rendered":"Get your subplots the way you want it with subplotHelper"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\"><span>Jiro<\/span><\/a><span>'s Pick this week is <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/71369\"><span>subplotHelper<\/span><\/a><span> by my <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/4690594\"><span>Frederick Zittrell<\/span><\/a><span>.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Did you know that <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/subplot.html\"><span style=' font-family: monospace;'>subplot<\/span><\/a><span> can be used to create non-uniformly distributed axes? For example,<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 1px solid rgb(191, 191, 191); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >figure<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >subplot(3,3,1), text(0.5,0.5,<\/span><span style=\"color: rgb(167, 9, 245);\">\"1\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"FontSize\"<\/span><span >,24,<\/span><span style=\"color: rgb(167, 9, 245);\">\"Color\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"red\"<\/span><span >)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >subplot(3,3,2), text(0.5,0.5,<\/span><span style=\"color: rgb(167, 9, 245);\">\"2\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"FontSize\"<\/span><span >,24,<\/span><span style=\"color: rgb(167, 9, 245);\">\"Color\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"red\"<\/span><span >)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >subplot(3,3,3), text(0.5,0.5,<\/span><span style=\"color: rgb(167, 9, 245);\">\"3\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"FontSize\"<\/span><span >,24,<\/span><span style=\"color: rgb(167, 9, 245);\">\"Color\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"red\"<\/span><span >)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >subplot(3,3,[4 7]), text([.5 .5],[.25 .75],[<\/span><span style=\"color: rgb(167, 9, 245);\">\"7\" \"4\"<\/span><span >],<\/span><span style=\"color: rgb(167, 9, 245);\">\"FontSize\"<\/span><span >,24,<\/span><span style=\"color: rgb(167, 9, 245);\">\"Color\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"red\"<\/span><span >)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(191, 191, 191); border-right: 1px solid rgb(191, 191, 191); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(191, 191, 191); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >subplot(3,3,[5 9]), text([.25 .25 .75 .75],[.25 .75 .25 .75],[<\/span><span style=\"color: rgb(167, 9, 245);\">\"8\" \"5\" \"9\" \"6\"<\/span><span >],<\/span><span style=\"color: rgb(167, 9, 245);\">\"FontSize\"<\/span><span >,24,<\/span><span style=\"color: rgb(167, 9, 245);\">\"Color\"<\/span><span >,<\/span><span style=\"color: rgb(167, 9, 245);\">\"red\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"0B395FB0\" prevent-scroll=\"true\" data-testid=\"output_0\" style=\"width: 1145px;\"><div class=\"figureElement eoOutputContent\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_subplothelper_1.png\" style=\"width: 560px; padding-bottom: 0px;\"><\/div><div class=\"outputLayer selectedOutputDecorationLayer doNotExport\"><\/div><div class=\"outputLayer activeOutputDecorationLayer doNotExport\"><\/div><div class=\"outputLayer scrollableOutputDecorationLayer doNotExport\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As you can see, the third input argument to <\/span><span style=' font-family: monospace;'>subplot<\/span><span> can be a vector that specifies the corners of the rectangular region. It's not too complicated, but it does require some thought to figure out the appropriate parameters.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span style=' font-family: monospace;'>subplotHelper<\/span><span> helps you get these parameters by allowing you to interactively select the layout. Here's the tool in action.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span><div style=\"width: 1000px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-16037-1\" width=\"1000\" height=\"620\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/subplothelper_video-1.mp4?_=1\" \/><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/subplothelper_video-1.mp4\">https:\/\/blogs.mathworks.com\/pick\/files\/subplothelper_video-1.mp4<\/a><\/video><\/div><\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Very nice!<\/span><\/div><h4  style = 'margin: 10px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 15px; font-weight: 700; text-align: left; '><span>Check out <\/span><span style=' font-family: monospace;'>tiledlayout<\/span><span> (introduced in R2019b)<\/span><\/h4><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>On a related note, if you're using R2019b or later, check out the new function <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/tiledlayout.html\"><span style=' font-family: monospace;'>tiledlayout<\/span><\/a><span> and <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/nexttile.html\"><span style=' font-family: monospace;'>nexttile<\/span><\/a><span>. These give you a bit more control and additional capabilities for axes layout over <\/span><span style=' font-family: monospace;'>subplot<\/span><span>. One of my favorite features of <\/span><span style=' font-family: monospace;'>tiledlayout<\/span><span> is the \"flow\" option that automatically adjusts the layout based on the figure size and shape.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span><div style=\"width: 1000px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-16037-2\" width=\"1000\" height=\"628\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/tiledlayout_video-1.mp4?_=2\" \/><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/tiledlayout_video-1.mp4\">https:\/\/blogs.mathworks.com\/pick\/files\/tiledlayout_video-1.mp4<\/a><\/video><\/div><\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Of course, <\/span><span style=' font-family: monospace;'>tiledlayout<\/span><span> can have non-uniform distribution, just like with <\/span><span style=' font-family: monospace;'>subplot<\/span><span>.<\/span><\/div><h4  style = 'margin: 10px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 15px; font-weight: 700; text-align: left; '><span>Comments<\/span><\/h4><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Give <\/span><span style=' font-family: monospace;'>subplotHelper<\/span><span> a try, and let us know what you think <\/span><a href = \"https:\/\/blogs.mathworks.com\/pick\/?p=16037#respond\"><span>here<\/span><\/a><span>.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a href=\"\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/subplothelper_screenshot.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Jiro's Pick this week is subplotHelper by my Frederick Zittrell.Did you know that subplot can be used to create non-uniformly distributed axes? For example,figuresubplot(3,3,1),... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2022\/07\/01\/get-your-subplots-the-way-you-want-it-with-subplothelper\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":16061,"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\/16037"}],"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=16037"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/16037\/revisions"}],"predecessor-version":[{"id":16109,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/16037\/revisions\/16109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/16061"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=16037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=16037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=16037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}