{"id":11651,"date":"2020-07-24T09:00:40","date_gmt":"2020-07-24T13:00:40","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=11651"},"modified":"2020-09-11T10:43:19","modified_gmt":"2020-09-11T14:43:19","slug":"zoom-plot","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2020\/07\/24\/zoom-plot\/","title":{"rendered":"Zoom Plot"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59857\">zoomPlot<\/a> by <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8689849\">Kelsey Bower<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n\r\n   <p>(No - it's not the matrix of faces that you see in a conference call!) My pick this week allows you to zoom in on specific region in a line plot.\r\n   <\/p>\r\n   <p>Let's plot some data:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">T = readtable(<span style=\"color: #A020F0\">'C:\\Documents\\MATLAB\\FlightTestData.xlsx'<\/span>);\r\nplot(T.LoadFactor);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/MainZoomPlot_01.png\"> <p>There are some interesting dynamics near the upper right hand corner. I'd like to show them with more detail.  I can simply add a zoomPlot to this.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[~, z] = zoomPlot((1:800).', T.LoadFactor, [615 740], [0.2 0.5 0.4 0.4]);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/MainZoomPlot_02.png\"> <p>The detail is more clear.  Now we can highlight the local minima and maxima in this zoomed in plot.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">xzoom = 615:740;\r\nloadfactorzoom = T.LoadFactor(xzoom);\r\nimax = islocalmax(loadfactorzoom, <span style=\"color: #A020F0\">'MinProminence'<\/span>, 0.05);\r\nimin = islocalmin(loadfactorzoom, <span style=\"color: #A020F0\">'MinProminence'<\/span>, 0.05);\r\nhold(z, <span style=\"color: #A020F0\">'on'<\/span>);\r\n\r\nplot(xzoom(imax),loadfactorzoom(imax), <span style=\"color: #A020F0\">'r*'<\/span>)\r\nplot(xzoom(imin),loadfactorzoom(imin), <span style=\"color: #A020F0\">'g*'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/MainZoomPlot_03.png\"> <p>Now if you did want a zoom plot like you'd see in a virtual meeting, use tiledlayout, which is new in R2019b and replaces subplot workflows.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure\r\nt = tiledlayout(<span style=\"color: #A020F0\">'flow'<\/span>, <span style=\"color: #A020F0\">'Padding'<\/span>, <span style=\"color: #A020F0\">'none'<\/span>, <span style=\"color: #A020F0\">'TileSpacing'<\/span>, <span style=\"color: #A020F0\">'none'<\/span>);\r\nimages = dir(fullfile(matlabroot, <span style=\"color: #A020F0\">'toolbox\\images\\imdata\\*.jpg'<\/span>));\r\n<span style=\"color: #0000FF\">for<\/span> ii = 1:numel(images)\r\n    nexttile(t)\r\n    imshow(fullfile(images(ii).folder, images(ii).name))\r\n<span style=\"color: #0000FF\">end<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/MainZoomPlot_05.png\"> <h3>Comments<a name=\"5\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=11651#respond\">here<\/a> or leave a <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59857#comments\">comment<\/a> for Kelsey.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_9bd4ea3a2043468f9d85a8675ca21fd8() {\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='9bd4ea3a2043468f9d85a8675ca21fd8 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 9bd4ea3a2043468f9d85a8675ca21fd8';\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 = 'Sean de Wolski';\r\n        copyright = 'Copyright 2020 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_9bd4ea3a2043468f9d85a8675ca21fd8()\"><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; R2020a<br><\/p>\r\n<\/div>\r\n<!--\r\n9bd4ea3a2043468f9d85a8675ca21fd8 ##### SOURCE BEGIN #####\r\n%% zoomPlot\r\n%\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59857 zoomPlot> by\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8689849 Kelsey Bower>.\r\n% \r\n\r\n%% \r\n% (No - it's not the matrix of faces that you see in a conference call!)\r\n% My pick this week allows you to zoom in on specific region in a line\r\n% plot.\r\n%\r\n% Let's plot some data:\r\n%\r\n\r\nT = readtable('C:\\Documents\\MATLAB\\Content\\demos\\Telemetry\\01 - Intro\\FlightTestData.xlsx');\r\nplot(T.LoadFactor);\r\n\r\n%%\r\n% There are some interesting dynamics near the upper right hand corner.\r\n% I'd like to show them with more detail.  I can simply add a zoomPlot to\r\n% this.\r\n%\r\n\r\n[~, z] = zoomPlot((1:800).', T.LoadFactor, [615 740], [0.2 0.5 0.4 0.4]);\r\n\r\n%%\r\n% The detail is more clear.  Now we can highlight the local minima and\r\n% maxima in this zoomed in plot.\r\n\r\nxzoom = 615:740;\r\nloadfactorzoom = T.LoadFactor(xzoom);\r\nimax = islocalmax(loadfactorzoom, 'MinProminence', 0.05);\r\nimin = islocalmin(loadfactorzoom, 'MinProminence', 0.05);\r\nhold(z, 'on');\r\n\r\nplot(xzoom(imax),loadfactorzoom(imax), 'r*')\r\nplot(xzoom(imin),loadfactorzoom(imin), 'g*')\r\n\r\n%%\r\n% Now if you did want a zoom plot like you'd see in a virtual meeting, use\r\n% tiledlayout, which is new in R2019b and replaces subplot workflows.\r\n\r\nfigure\r\nt = tiledlayout('flow', 'Padding', 'none', 'TileSpacing', 'none');\r\nimages = dir(fullfile(matlabroot, 'toolbox\\images\\imdata\\*.jpg'));\r\nfor ii = 1:numel(images)\r\n    nexttile(t)\r\n    imshow(fullfile(images(ii).folder, images(ii).name))\r\nend\r\n\r\n\r\n%% Comments\r\n% \r\n% Give it a try and let us know what you think\r\n% <http:\/\/blogs.mathworks.com\/pick\/?p=11651#respond here> or leave a\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59857#comments\r\n% comment> for Kelsey.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 9bd4ea3a2043468f9d85a8675ca21fd8\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/MainZoomPlot_03.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is zoomPlot by Kelsey Bower.\r\n      \r\n   \r\n\r\n   (No - it's not the matrix of faces that you see in a conference call!) My pick this week allows... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2020\/07\/24\/zoom-plot\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":11663,"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\/11651"}],"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=11651"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11651\/revisions"}],"predecessor-version":[{"id":11667,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11651\/revisions\/11667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/11663"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=11651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=11651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=11651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}