{"id":2932,"date":"2011-10-07T11:53:05","date_gmt":"2011-10-07T11:53:05","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/07\/box-plot-scatter-plot\/"},"modified":"2011-10-07T11:53:05","modified_gmt":"2011-10-07T11:53:05","slug":"box-plot-scatter-plot","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/07\/box-plot-scatter-plot\/","title":{"rendered":"Box plot + Scatter plot"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\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\/26508-notboxplot\"><tt>notBoxPlot<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/49773\">Rob Campbell<\/a>.\r\n   <\/p>\r\n   <p>If you have ever used <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/stats\/boxplot.html\"><tt>boxplot<\/tt><\/a> from the <a href=\"https:\/\/www.mathworks.com\/products\/statistics\/\">Statistics Toolbox<\/a>, you know the value of being able to visualize statistical information on a plot.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">pts1 = randn(20, 5);\r\npts2 = randn(10, 40);\r\n\r\nfigure;\r\nsubplot(2, 1, 1);\r\nboxplot(pts1);\r\nsubplot(2, 1, 2);\r\nboxplot(pts2, <span style=\"color: #A020F0\">'plotstyle'<\/span>, <span style=\"color: #A020F0\">'compact'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_notboxplot\/potw_notboxplot_01.png\"> <p>While box plots give the statistical information, you may also want the additional insight that you get from the raw data\r\n      points. You can do that by <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/hold.html\">holding<\/a> the graph and plotting the data. Or you can just use Rob's function, which overlays the original data in a clever way, with\r\n      some jitter to better distinguish the points.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure;\r\nsubplot(2, 1, 1)\r\nnotBoxPlot(pts1);\r\nsubplot(2, 1, 2)\r\nh = notBoxPlot(pts2);\r\nd = [h.data];\r\nset(d(1:4:end), <span style=\"color: #A020F0\">'markerfacecolor'<\/span>, [0.4,1,0.4], <span style=\"color: #A020F0\">'color'<\/span>, [0,0.4,0]);\r\nset(d, <span style=\"color: #A020F0\">'markersize'<\/span>, 3);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_notboxplot\/potw_notboxplot_02.png\"> <p>There are quite a few <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=boxplot\">entries<\/a> on File Exchange that are related to boxplots, but I was quite intrigued by Rob's way of visualizing the data points. I like\r\n      how he extended an existing functionality in the toolbox to create his reusable function. His function has a well-written\r\n      help text with many examples, and I appreciate the healthy discussions he has on the entry page with some of the users of\r\n      his function.\r\n   <\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2932#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26508-notboxplot#comments\">comment<\/a> for Rob.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_2c9f38ee482c4deda7b09bb02ee716f8() {\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='2c9f38ee482c4deda7b09bb02ee716f8 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 2c9f38ee482c4deda7b09bb02ee716f8';\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 2011 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_2c9f38ee482c4deda7b09bb02ee716f8()\"><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.13<br><\/p>\r\n<\/div>\r\n<!--\r\n2c9f38ee482c4deda7b09bb02ee716f8 ##### 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\/26508-notboxplot |notBoxPlot|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/49773 Rob\r\n% Campbell>.\r\n%\r\n% If you have ever used\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/toolbox\/stats\/boxplot.html |boxplot|> from\r\n% the <https:\/\/www.mathworks.com\/products\/statistics\/ Statistics Toolbox>,\r\n% you know the value of being able to visualize statistical information on\r\n% a plot.\r\n\r\npts1 = randn(20, 5);\r\npts2 = randn(10, 40);\r\n\r\nfigure;\r\nsubplot(2, 1, 1);\r\nboxplot(pts1);\r\nsubplot(2, 1, 2);\r\nboxplot(pts2, 'plotstyle', 'compact');\r\n\r\n%%\r\n% While box plots give the statistical information, you may also want the\r\n% additional insight that you get from the raw data points. You can do that\r\n% by <https:\/\/www.mathworks.com\/help\/releases\/R2011b\/techdoc\/ref\/hold.html holding> the\r\n% graph and plotting the data. Or you can just use Rob's function, which\r\n% overlays the original data in a clever way, with some jitter to better\r\n% distinguish the points.\r\n\r\nfigure;\r\nsubplot(2, 1, 1)\r\nnotBoxPlot(pts1);\r\nsubplot(2, 1, 2)\r\nh = notBoxPlot(pts2);\r\nd = [h.data];\r\nset(d(1:4:end), 'markerfacecolor', [0.4,1,0.4], 'color', [0,0.4,0]);\r\nset(d, 'markersize', 3);\r\n  \r\n%%\r\n% There are quite a few\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=boxplot\r\n% entries> on File Exchange that are related to boxplots, but I was quite\r\n% intrigued by Rob's way of visualizing the data points. I like how he\r\n% extended an existing functionality in the toolbox to create his reusable\r\n% function. His function has a well-written help text with many examples,\r\n% and I appreciate the healthy discussions he has on the entry page with\r\n% some of the users of his function.\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2932#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/26508-notboxplot#comments\r\n% comment> for Rob.\r\n\r\n##### SOURCE END ##### 2c9f38ee482c4deda7b09bb02ee716f8\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is notBoxPlot by Rob Campbell.\r\n   \r\n   If you have ever used boxplot from the Statistics Toolbox, you know the value of being able to visualize statistical information on... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/07\/box-plot-scatter-plot\/\">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\/2932"}],"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=2932"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2932\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}