{"id":5621,"date":"2014-11-14T09:00:21","date_gmt":"2014-11-14T14:00:21","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5621"},"modified":"2014-11-12T12:20:11","modified_gmt":"2014-11-12T17:20:11","slug":"votebar","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/11\/14\/votebar\/","title":{"rendered":"Votebar"},"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\/answers\/contributors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27545-votebar\">votebar<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/53328\">paul koch<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>Paul's <tt>votebar<\/tt> is a nice utility for viewing cylindrical three dimensional bar plots like you would see after an election.  For example:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">n = 4;\r\npct = randfixedsum(n,1,100,0,100); <span style=\"color: #228B22\">% File Exchange<\/span>\r\nvotebar(100, pct, parula(n), 0);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainvotebar\/mainvotebar_01.png\"> <p>Or in the case of the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/149-is-my-wife-right\">\"Is my wife right?\"<\/a> CODY problem:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">votebar(100,[100 0],[0 1 0; 0 0 1],0);\r\ntext(1.5,-1,<span style=\"color: #A020F0\">'Yes'<\/span>,<span style=\"color: #A020F0\">'FontSize'<\/span>,20)\r\ntext(1.5,1.5,<span style=\"color: #A020F0\">'No'<\/span>,<span style=\"color: #A020F0\">'FontSize'<\/span>,20)\r\ntitle(<span style=\"color: #A020F0\">'Is My Wife Right?'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainvotebar\/mainvotebar_02.png\"> <p>Let's take a look at this with the election data from the 2014 Massachusetts gubernatorial race.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% Data and setup<\/span>\r\nvotes = [1041640 1001279 71144 19192 16125];\r\npct = votes.\/sum(votes)*100;\r\nnames = {<span style=\"color: #A020F0\">'Charlie Baker'<\/span>, <span style=\"color: #A020F0\">'Martha Coakley'<\/span>, <span style=\"color: #A020F0\">'Evan Falchuk'<\/span>, <span style=\"color: #A020F0\">'Scott Lively'<\/span>, <span style=\"color: #A020F0\">'Jeff McCormick'<\/span>};\r\ncolors = [1 0 0; 0 0 1; 0.541 0.706 0.486]; <span style=\"color: #228B22\">% RGBcolors<\/span>\r\nidx = [1 2 3 3 3].'; <span style=\"color: #228B22\">% Index into colors<\/span>\r\n\r\n<span style=\"color: #228B22\">% Votebar<\/span>\r\nhp = votebar(100, pct, colors(idx,:), 0);\r\n\r\n<span style=\"color: #228B22\">% Decorating<\/span>\r\nlegend(hp(3,:),names)\r\nlighting <span style=\"color: #A020F0\">gouraud<\/span>\r\nmaterial <span style=\"color: #A020F0\">shiny<\/span>\r\ntitle(<span style=\"color: #A020F0\">'Massachusetts Gubernatorial Results'<\/span>)\r\nview(84,14)\r\ntext(-6.5,-2,<span style=\"color: #A020F0\">'%'<\/span>,<span style=\"color: #A020F0\">'FontSize'<\/span>,20)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainvotebar\/mainvotebar_03.png\"> <p>Source: <i>http:\/\/www.politico.com\/2014-election\/results\/map\/governor\/massachusetts\/#.VGIlaE1OXcw<\/i><\/p>\r\n   <h3>Comments<a name=\"5\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5621#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27545-votebar#comments\">comment<\/a> for Paul.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_787d98e6ff344f9d9673184699994bbf() {\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='787d98e6ff344f9d9673184699994bbf ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 787d98e6ff344f9d9673184699994bbf';\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 2014 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_787d98e6ff344f9d9673184699994bbf()\"><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; R2014b<br><\/p>\r\n<\/div>\r\n<!--\r\n787d98e6ff344f9d9673184699994bbf ##### SOURCE BEGIN #####\r\n%% Vote Bar\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/answers\/contributors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27545-votebar votebar> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/53328 paul koch>.\r\n% \r\n\r\n%% \r\n% Paul's |votebar| is a nice utility for viewing cylindrical three\r\n% dimensional bar plots like you would see after an election.  For example:\r\n\r\nn = 4;\r\npct = randfixedsum(n,1,100,0,100); % File Exchange\r\nvotebar(100, pct, parula(n), 0);\r\n\r\n%%\r\n% Or in the case of the <https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/149-is-my-wife-right \"Is my wife right?\"> CODY problem:\r\n\r\nvotebar(100,[100 0],[0 1 0; 0 0 1],0);\r\ntext(1.5,-1,'Yes','FontSize',20)\r\ntext(1.5,1.5,'No','FontSize',20)\r\ntitle('Is My Wife Right?')\r\n\r\n%% \r\n% Let's take a look at this with the election data from the 2014\r\n% Massachusetts gubernatorial race.\r\n\r\n% Data and setup\r\nvotes = [1041640 1001279 71144 19192 16125];\r\npct = votes.\/sum(votes)*100;\r\nnames = {'Charlie Baker', 'Martha Coakley', 'Evan Falchuk', 'Scott Lively', 'Jeff McCormick'};\r\ncolors = [1 0 0; 0 0 1; 0.541 0.706 0.486]; % RGBcolors\r\nidx = [1 2 3 3 3].'; % Index into colors\r\n\r\n% Votebar\r\nhp = votebar(100, pct, colors(idx,:), 0);\r\n\r\n% Decorating\r\nlegend(hp(3,:),names)\r\nlighting gouraud\r\nmaterial shiny\r\ntitle('Massachusetts Gubernatorial Results')\r\nview(84,14)\r\ntext(-6.5,-2,'%','FontSize',20)\r\n\r\n%% \r\n% Source:\r\n% _http:\/\/www.politico.com\/2014-election\/results\/map\/governor\/massachusetts\/#.VGIlaE1OXcw_\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=5621#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27545-votebar#comments\r\n% comment> for Paul.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 787d98e6ff344f9d9673184699994bbf\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainvotebar\/mainvotebar_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is votebar by paul koch.\r\n      \r\n   \r\n   Paul's votebar is a nice utility for viewing cylindrical three dimensional bar plots like you would see after an election.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/11\/14\/votebar\/\">read more >><\/a><\/p>","protected":false},"author":87,"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\/5621"}],"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=5621"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5621\/revisions"}],"predecessor-version":[{"id":5812,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5621\/revisions\/5812"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}