{"id":2348,"date":"2008-11-21T16:11:04","date_gmt":"2008-11-21T16:11:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/11\/21\/breaking-a-plot-to-improve-visualization\/"},"modified":"2016-05-18T11:30:27","modified_gmt":"2016-05-18T15:30:27","slug":"breaking-a-plot-to-improve-visualization","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/11\/21\/breaking-a-plot-to-improve-visualization\/","title":{"rendered":"Breaking a plot to improve visualization"},"content":{"rendered":"<div class=\"content\">\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n\t<li><a href=\"#2\">Traditional plot<\/a><\/li>\r\n\t<li><a href=\"#3\">BREAKPLOT<\/a><\/li>\r\n\t<li><a href=\"#4\">Some things I particularly like about this function<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\nSuppose you wanted to plot data that spanned two distinct ranges of your dependent variable. Showing all the data on a single\r\nplot would waste valuable real estate, and changing to a log scale might obscure some of your data. Classically, you might\r\nthink of using the SUBPLOT function to create two separate axes to visualize the data. Alternatively, you might want to create\r\na single axes, and to break it to reflect the different ranges. Michael Robbins's <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/21864-breakplot\">BREAKPLOT<\/a> makes short work of that task.\r\n\r\nConsider, for example, that you had some sampled engine-speed data collected during two times in the engine's cycle. The first\r\n100 data points are colleced (at sampling times 1:100) while the engine is idling, and the second 100 data are collected (at\r\nt = 101:200) while the engine is being revved:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">sampleTimes = 1:200;\r\nRPM = [600+rand(1,100)*500, 5500+rand(1,100)*2500];<\/pre>\r\n<h3>Traditional plot<a name=\"2\"><\/a><\/h3>\r\nNote all the wasted \"white space\" in the traditional plot of these data. Also note how tightly clustered the data can be.\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">plot(sampleTimes,RPM,<span style=\"color: #a020f0;\">'r.'<\/span>)<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/breakplot_potw_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<h3>BREAKPLOT<a name=\"3\"><\/a><\/h3>\r\nNow consider how Michael's function allows you to break the y-axis to reflect the range change:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">BreakPlot(sampleTimes,RPM,1500,5000,<span style=\"color: #a020f0;\">'Line'<\/span>);<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/breakplot_potw_02.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<h3>Some things I particularly like about this function<a name=\"4\"><\/a><\/h3>\r\nFirst, this nicely extends the powerful visualization capabilities MATLAB provides out of the box--and the ability to customize\r\nfunctions is often critical.\r\n\r\nSecond, Michael provided nice options for different break visualizations. The default 'RPatch' produces a ragged patch across\r\nthe axis. 'Line' (shown above) shows hash marks where the axis is broken. And 'Patch' produces a smoother break reaching across\r\nthe axis.\r\n\r\nFinally, I appreciate Michael's responsiveness when I asked him to address an issue I saw with an earlier version of his code.\r\nThis demonstrates yet again that the File Exchange is dynamic and ever-improving!\r\n\r\nIf you have any custom visualizations along these lines, tell us about them in the Comments box below, and share them on the\r\nFile Exchange!\r\n\r\nAnd by the way, next Friday is the day after Thanksgiving. Bob, Jiro and I will be taking the day off to digest our turkey\r\ndinners, and we hope you'll be doing the same. Look for our next Pick of the Week on December 5. Happy Thanksgiving, everyone!\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_46038d1f833e419ba503dcd13dc90124() {\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='46038d1f833e419ba503dcd13dc90124 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 46038d1f833e419ba503dcd13dc90124';\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 = 'Brett Shoelson';\r\n        copyright = 'Copyright 2008 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\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>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.7<\/p>\r\n\r\n<\/div>\r\n<!--\r\n46038d1f833e419ba503dcd13dc90124 ##### SOURCE BEGIN #####\r\n%%\r\n%\r\n% Suppose you wanted to plot data that spanned two distinct ranges of your dependent variable. Showing all the data on a single plot would waste valuable real estate, and changing to a log scale might obscure some of your data. Classically, you might think of using the SUBPLOT  function to create two separate axes to visualize the data. Alternatively, you might want to create a single axes, and to break it to reflect the different ranges. <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectId=828141&objectType=author Michael Robbins>'s <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/21864-breakplot BREAKPLOT> makes short work of that task.\r\n%\r\n% Consider, for example, that you had some sampled engine-speed data collected during two times in the engine's cycle. The first 100 data points are colleced (at sampling times 1:100) while the engine is idling, and the second 100 data are collected (at t = 101:200) while the engine is being revved:\r\nsampleTimes = 1:200;\r\nRPM = [600+rand(1,100)*500, 5500+rand(1,100)*2500];\r\n\r\n%% Traditional plot\r\n% Note all the wasted \"white space\" in the traditional plot of these data. Also note how tightly clustered the data can be.\r\nplot(sampleTimes,RPM,'r.')\r\n\r\n%% BREAKPLOT\r\n% Now consider how Michael's function allows you to\r\n% break the y-axis to reflect the range change:\r\nBreakPlot(sampleTimes,RPM,1500,5000,'Line');\r\n\r\n%% Some things I particularly like about this function\r\n% First, this nicely extends the powerful visualization\r\n% capabilities MATLAB provides out of the boxREPLACE_WITH_DASH_DASHand the ability to customize functions is often critical.\r\n%\r\n% Second, Michael provided nice options for different\r\n% break visualizations. The default 'RPatch' produces a\r\n% ragged patch across the axis. 'Line' (shown above)\r\n% shows hash marks where the axis is broken. And\r\n% 'Patch' produces a smoother break reaching across the axis.\r\n%\r\n% Finally, I appreciate Michael's responsiveness when I\r\n% asked him to address an issue I saw with an earlier\r\n% version of his code. This demonstrates yet again that\r\n% the File Exchange is dynamic and ever-improving!\r\n\r\n%%\r\n% If you have any custom visualizations along these\r\n% lines, tell us about them in the Comments box below, and share them on the File\r\n% Exchange!\r\n%\r\n% And by the way, next Friday is the day\r\n% after Thanksgiving. Bob, Jiro and I will be taking the day off to\r\n% digest our turkey dinners, and we hope you'll be\r\n% doing the same. Look for our next Pick of the Week on December 5. Happy Thanksgiving, everyone!\r\n\r\n##### SOURCE END ##### 46038d1f833e419ba503dcd13dc90124\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\nContents\r\n\r\n\r\n\tTraditional plot\r\n\tBREAKPLOT\r\n\tSome things I particularly like about this function\r\n\r\n\r\nSuppose you wanted to plot data that spanned two distinct ranges of your dependent variable.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/11\/21\/breaking-a-plot-to-improve-visualization\/\">read more >><\/a><\/p>","protected":false},"author":34,"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\/2348"}],"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\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2348"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2348\/revisions"}],"predecessor-version":[{"id":7348,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2348\/revisions\/7348"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}