{"id":2373,"date":"2009-02-06T06:00:50","date_gmt":"2009-02-06T06:00:50","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/02\/06\/plotaxisatorigin\/"},"modified":"2009-02-09T15:13:16","modified_gmt":"2009-02-09T15:13:16","slug":"plotaxisatorigin","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/02\/06\/plotaxisatorigin\/","title":{"rendered":"PlotAxisAtOrigin"},"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\/fileexchange\/authors\/5021\">Bob<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/10473-plotaxisatorigin\">PlotAxisAtOrigin<\/a> by Shanrong Zhang.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>As an application engineer I showed MATLAB to a lot of people. Occasionally when I presented graphics capabilities someone\r\n      would ask how to make plots where the X and Y axes lines go through the origin. You know: the way we learned to draw them\r\n      in school. By default MATLAB puts the X axes on bottom and the Y axes on the left.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">x = -2*pi:pi\/10:2*pi;\r\ny = sin(x);\r\nplot(x,y)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/plot_axis_at_origin_01.png\"> <p>While the <tt>xAxisLocation<\/tt> can be set to <tt>top<\/tt>, and the <tt>yAxisLocation<\/tt> can be <tt>right<\/tt>, neither has an <tt>origin<\/tt> option for example. So, instead, I usually suggested drawing lines through the origin. In fact, prior \"Pick of the Week\"\r\n      star Brandon Kuczenski made that trivial with <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/1039-hline-and-vline\">hline and vline<\/a>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">hline(0)\r\nvline(0)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/plot_axis_at_origin_02.png\"> <p>Not satisfied? Neither was Shanrong. Hence, <tt>PlotAxisAtOrigin<\/tt>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">PlotAxisAtOrigin(x,y)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/plot_axis_at_origin_03.png\"> <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2373#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_38dc89924bf345f3aa539bcea1186ea8() {\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='38dc89924bf345f3aa539bcea1186ea8 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 38dc89924bf345f3aa539bcea1186ea8';\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 = 'Robert Bemis';\r\n        copyright = 'Copyright 2009 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_38dc89924bf345f3aa539bcea1186ea8()\"><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.8<br><\/p>\r\n<\/div>\r\n<!--\r\n38dc89924bf345f3aa539bcea1186ea8 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021 Bob>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/10473-plotaxisatorigin PlotAxisAtOrigin>\r\n% by Shanrong Zhang.\r\n%%\r\n% As an application engineer I showed MATLAB to a lot of people. Occasionally\r\n% when I presented graphics capabilities someone would ask how to make plots\r\n% where the X and Y axes lines go through the origin. You know: the way we\r\n% learned to draw them in school. By default MATLAB puts the X axes on bottom\r\n% and the Y axes on the left.\r\nx = -2*pi:pi\/10:2*pi;\r\ny = sin(x);\r\nplot(x,y)\r\n%%\r\n% While the |xAxisLocation| can be set to |top|, and the |yAxisLocation| can\r\n% be |right|, neither has an |origin| option for example. So, instead, I\r\n% usually suggested drawing lines through the origin. In fact, prior \"Pick of\r\n% the Week\" star Brandon Kuczenski made that trivial with \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/1039-hline-and-vline hline and vline>.\r\nhline(0)\r\nvline(0)\r\n%%\r\n% Not satisfied? Neither was Shanrong. Hence, |PlotAxisAtOrigin|.\r\nPlotAxisAtOrigin(x,y)\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2373#respond Comments?>\r\n\r\n##### SOURCE END ##### 38dc89924bf345f3aa539bcea1186ea8\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Bob's pick this week is PlotAxisAtOrigin by Shanrong Zhang.\r\n      \r\n   \r\n   As an application engineer I showed MATLAB to a lot of people. Occasionally when I presented graphics... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/02\/06\/plotaxisatorigin\/\">read more >><\/a><\/p>","protected":false},"author":46,"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\/2373"}],"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\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2373"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2373\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}