{"id":3126,"date":"2019-02-22T11:12:57","date_gmt":"2019-02-22T16:12:57","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=3126"},"modified":"2019-11-01T22:34:21","modified_gmt":"2019-11-02T02:34:21","slug":"making-your-plot-lines-thicker","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2019\/02\/22\/making-your-plot-lines-thicker\/","title":{"rendered":"Making your plot lines thicker"},"content":{"rendered":"<div class=\"content\"><p>Today's blog post is dedicated to everyone whose eyes aren't as young as they used to be.<\/p><p>In last week's blog post on pursuit curves, I showed this figure:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit-curves-thick.png\" alt=\"\"> <\/p><p>If you ran my code exactly as I posted it, though, you probably wouldn't see exactly the same thing. You would see something like this instead:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/pursuit-curves-thin.png\" alt=\"\"> <\/p><p>Do you see the difference? Exactly what you see will vary depending on your computer and your display resolution, but the original image from my blog post has thicker colored lines.<\/p><p>That's because I don't use the default line thickness for my plots.<\/p><p>Let me show you what I mean. Here's a basic example of <tt>plot<\/tt> from the MATLAB documentation:<\/p><pre class=\"codeinput\">x = linspace(-2*pi,2*pi);\r\ny1 = sin(x);\r\ny2 = cos(x);\r\n\r\nfigure\r\nplot(x,y1,x,y2)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/default_line_width_01.png\" alt=\"\"> <p>The plot above uses the default MATLAB line width of 0.5 points. Here's where I have to wave my hands a little. Because of the way the figure above was captured for display in your browser, the lines probably appear a little thicker than 0.5 points. On a high resolution display, however, the plotted lines are pretty close to 0.5 points thick.<\/p><p>And, to my eyes, that's too thin to see the colors clearly.<\/p><p>So, I like to plot thicker lines, roughly 1.5-2.0 points. You can do that in each call to <tt>plot<\/tt> by using the <tt>LineWidth<\/tt> parameter, like this:<\/p><pre class=\"codeinput\">plot(x,y1,x,y2,<span class=\"string\">'LineWidth'<\/span>,2.0)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/default_line_width_02.png\" alt=\"\"> <p>But then you have to remember to add the <tt>LineWidth<\/tt> parameter all the time. It turns out that there's a way to get MATLAB to draw all plotted lines thicker by default. Here it is:<\/p><pre class=\"codeinput\">set(groot,<span class=\"string\">'defaultLineLineWidth'<\/span>,2.0)\r\n<\/pre><p>This odd-looking line of code sets the default <tt>LineWidth<\/tt> property for <tt>line<\/tt> objects to 2.0. For a full explanation of the MATLAB system for setting default graphics object properties, see <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/creating_plots\/default-property-values.html\">Default Property Values<\/a> in the MATLAB documentation.<\/p>\r\n\r\n<p>\r\n<em>\r\nUpdate: Using a thicker line width might only work well for high-DPI monitors. Blog reader Gang Yao pointed out that using 2-pt. lines can make markers indistinct, and I can confirm that observation when not using a high-DPI monitor. After some additional experimentation, I found that using 1.5-pt. lines on a high-DPI monitor works a little better.\r\n<\/em>\r\n<\/p>\r\n\r\n<p>This default setting does not persist between MATLAB sessions, though. If you want to do this for each MATLAB session, put the call to <tt>set<\/tt> into a file called <tt>startup.m<\/tt> that is located in your <i>user path<\/i> folder. Run the <tt>userpath<\/tt> function to see where that is. Here's mine:<\/p><pre class=\"codeinput\">userpath\r\n<\/pre><pre class=\"codeoutput\">\r\nans =\r\n\r\n    '\/Users\/steve\/OneDrive - MathWorks\/MATLAB'\r\n\r\n<\/pre><p>You can also use the <tt>userpath<\/tt> function to change your user path location, if you don't like the default location chosen by MATLAB. (That's what I did.)<\/p><p>For more information, see the function reference pages for <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/startup.html\"><tt>startup<\/tt><\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/userpath.html\"><tt>userpath<\/tt><\/a>.<\/p><p>Do you like thicker plotted lines too? Or is it just me?<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_62b3518006eb4b918114e27dd8276a9c() {\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='62b3518006eb4b918114e27dd8276a9c ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 62b3518006eb4b918114e27dd8276a9c';\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        copyright = 'Copyright 2019 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_62b3518006eb4b918114e27dd8276a9c()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2018b<br><\/p><\/div><!--\r\n62b3518006eb4b918114e27dd8276a9c ##### SOURCE BEGIN #####\r\n%%\r\n% Today's blog post is dedicated to everyone whose eyes aren't as young\r\n% as they used to be.\r\n%\r\n% In last week's blog post on pursuit curves, I showed this figure:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_04.png>>\r\n%\r\n% If you ran my code exactly as I posted it, though, you probably\r\n% wouldn't see exactly the same thing. You would see something like this\r\n% instead:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/pursuit_curves_thin_04.png>>\r\n%\r\n% Do you see the difference? Exactly what you see will vary depending on\r\n% your computer and your display resolution, but the original image from\r\n% my blog post has thicker colored lines.\r\n%\r\n% That's because I don't use the default line thickness for my plots.\r\n%\r\n% Let me show you what I mean. Here's a basic example of |plot| from the\r\n% MATLAB documentation:\r\n\r\nx = linspace(-2*pi,2*pi);\r\ny1 = sin(x);\r\ny2 = cos(x);\r\n\r\nfigure\r\nplot(x,y1,x,y2)\r\n\r\n%%\r\n% The plot above uses the default MATLAB line width of 0.5 points.\r\n% Here's where I have to wave my hands a little. Because of the way the\r\n% figure above was captured for display in your browser, the lines\r\n% probably appear a little thicker than 0.5 points. On a high resolution\r\n% display, however, the plotted lines are pretty close to 0.5 points\r\n% thick.\r\n%\r\n% And, to my eyes, that's too thin to see the colors clearly.\r\n%\r\n% So, I like to plot thicker lines, roughly 1.5-2.0 points. You can do\r\n% that in each call to |plot| by using the |LineWidth| parameter, like\r\n% this:\r\n\r\nplot(x,y1,x,y2,'LineWidth',2.0)\r\n\r\n%%\r\n% But then you have to remember to add the |LineWidth| parameter all\r\n% the time. It turns out that there's a way to get MATLAB to draw all\r\n% plotted lines thicker by default. Here it is:\r\n\r\nset(groot,'defaultLineLineWidth',2.0)\r\n\r\n%%\r\n% This odd-looking line of code sets the default |LineWidth| property\r\n% for |line| objects to 2.0. For a full explanation of the MATLAB system\r\n% for setting default graphics object properties, see\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/creating_plots\/default-property-values.html \r\n% Default Property Values> in the MATLAB documentation.\r\n%\r\n% This default setting does not persist between MATLAB sessions, though.\r\n% If you want to do this for each MATLAB session, put the call to |set|\r\n% into a file called |startup.m| that is located in your _user path_\r\n% folder. Run the |userpath| function to see where that is. Here's mine:\r\n\r\nuserpath\r\n\r\n%%\r\n% You can also use the |userpath| function to change your user path\r\n% location, if you don't like the default location chosen by MATLAB.\r\n% (That's what I did.)\r\n%\r\n% For more information, see the function reference pages for\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/startup.html |startup|> and\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/userpath.html |userpath|>.\r\n%\r\n% Do you like thicker plotted lines too? Or is it just me?\r\n##### SOURCE END ##### 62b3518006eb4b918114e27dd8276a9c\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/steve\/files\/default_line_width_02.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Today's blog post is dedicated to everyone whose eyes aren't as young as they used to be.In last week's blog post on pursuit curves, I showed this figure: If you ran my code exactly as I posted it,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2019\/02\/22\/making-your-plot-lines-thicker\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":3140,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[74,725,1227,32,68,34,1231,1229],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3126"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=3126"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3126\/revisions"}],"predecessor-version":[{"id":3152,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/3126\/revisions\/3152"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media\/3140"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=3126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=3126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=3126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}