{"id":2521,"date":"2010-01-15T15:09:01","date_gmt":"2010-01-15T15:09:01","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/15\/fixing-postscript-lines\/"},"modified":"2010-01-15T15:09:01","modified_gmt":"2010-01-15T15:09:01","slug":"fixing-postscript-lines","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/15\/fixing-postscript-lines\/","title":{"rendered":"Fixing PostScript Lines"},"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\/23604-fix-lines\"><tt>fix_lines<\/tt><\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29192\">Oliver Woodford<\/a>.\r\n   <\/p>\r\n   <p>Have you ever generated PostScript files (such as EPS files) from your MATLAB graphs? I had to do that numerous times when\r\n      I was in grad school and creating graphics for my publications. You can do extensive customization of your plot using <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/creating_plots\/f6-698.html\">basic plotting commands<\/a> or <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/creating_plots\/f7-20419.html\">handle graphics<\/a>. I also wrote a guest blog post, <a href=\"https:\/\/blogs.mathworks.com\/loren\/2007\/12\/11\/making-pretty-graphs\/\">\"Making Pretty Graphs\"<\/a>, on Loren's Blog.\r\n   <\/p>\r\n   <p>Oliver's <tt>fix_lines<\/tt> comes into play at the final step. Let's say that we have the following graph. A lot of journal publications only accept\r\n      black and white graphics. In that case, we have to make use of different line styles and thicknesses, instead of color.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">x = 0:0.01:10;\r\ny1 = sin(x);\r\ny2 = cos(x);\r\ny3 = sin(0.7*x) + 0.5*cos(1.3*x);\r\ny4 = 1.5*sin(0.5*x) + 0.8*cos(0.9*x);\r\nh = plot(x, y1, <span style=\"color: #A020F0\">'k-'<\/span>, x, y2, <span style=\"color: #A020F0\">'k:'<\/span>, x, y3, <span style=\"color: #A020F0\">'k-.'<\/span>, x, y4, <span style=\"color: #A020F0\">'k--'<\/span>);\r\nset(h, <span style=\"color: #A020F0\">'LineWidth'<\/span>, 1.5);\r\nlegend(<span style=\"color: #A020F0\">'Data 1'<\/span>, <span style=\"color: #A020F0\">'Data 2'<\/span>, <span style=\"color: #A020F0\">'Data 3'<\/span>, <span style=\"color: #A020F0\">'Data 4'<\/span>, <span style=\"color: #A020F0\">'Location'<\/span>, <span style=\"color: #A020F0\">'Best'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/potw_fixlines_01.png\"> <p>We can create an EPS file.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">print <span style=\"color: #A020F0\">-deps2<\/span> <span style=\"color: #A020F0\">-r600<\/span> <span style=\"color: #A020F0\">fig1.eps<\/span><\/pre><p>As we can seen below (left), the dotted and dash-dot lines need a little bit of tweaking. One way is to edit the EPS file\r\n      using an external software. Or, you can use <tt>fix_lines<\/tt>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">fix_lines(<span style=\"color: #A020F0\">'fig1.eps'<\/span>, <span style=\"color: #A020F0\">'fig1_fixed.eps'<\/span>);<\/pre><p>Notice that the lines look better after it's been \"fixed\" (right).<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/original_fixed.png\"> <\/p>\r\n   <p>I love this because it allows me to do everything in MATLAB, from analysis to the final graph. Oliver's code is very well\r\n      commented, so it's easy to follow what he's doing. Let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2521#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_810c0da737424631acf48bcfdd7f9c2a() {\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='810c0da737424631acf48bcfdd7f9c2a ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 810c0da737424631acf48bcfdd7f9c2a';\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 2010 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_810c0da737424631acf48bcfdd7f9c2a()\"><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.9<br><\/p>\r\n<\/div>\r\n<!--\r\n810c0da737424631acf48bcfdd7f9c2a ##### 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\/23604-fix-lines |fix_lines|>\r\n% by <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29192\r\n% Oliver Woodford>.\r\n%\r\n% Have you ever generated PostScript files (such as EPS files) from your\r\n% MATLAB graphs? I had to do that numerous times when I was in grad school\r\n% and creating graphics for my publications. You can do extensive\r\n% customization of your plot using\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/creating_plots\/f6-698.html\r\n% basic plotting commands> or\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/creating_plots\/f7-20419.html\r\n% handle graphics>. I also wrote a guest blog post,\r\n% <https:\/\/blogs.mathworks.com\/loren\/2007\/12\/11\/making-pretty-graphs\/\r\n% \"Making Pretty Graphs\">, on Loren's Blog.\r\n%\r\n% Oliver's |fix_lines| comes into play at the final step. Let's say that we\r\n% have the following graph. A lot of journal publications only accept black\r\n% and white graphics. In that case, we have to make use of different line\r\n% styles and thicknesses, instead of color.\r\n\r\nx = 0:0.01:10;\r\ny1 = sin(x);\r\ny2 = cos(x);\r\ny3 = sin(0.7*x) + 0.5*cos(1.3*x);\r\ny4 = 1.5*sin(0.5*x) + 0.8*cos(0.9*x);\r\nh = plot(x, y1, 'k-', x, y2, 'k:', x, y3, 'k-.', x, y4, 'kREPLACE_WITH_DASH_DASH');\r\nset(h, 'LineWidth', 1.5);\r\nlegend('Data 1', 'Data 2', 'Data 3', 'Data 4', 'Location', 'Best');\r\n\r\n%%\r\n% We can create an EPS file.\r\n\r\nprint -deps2 -r600 fig1.eps\r\n\r\n%%\r\n% As we can seen below (left), the dotted and dash-dot lines need a little\r\n% bit of tweaking. One way is to edit the EPS file using an external\r\n% software. Or, you can use |fix_lines|.\r\n\r\nfix_lines('fig1.eps', 'fig1_fixed.eps');\r\n\r\n%%\r\n% Notice that the lines look better after it's been \"fixed\" (right).\r\n%\r\n% <<original_fixed.png>>\r\n%\r\n% I love this because it allows me to do everything in MATLAB, from\r\n% analysis to the final graph. Oliver's code is very well commented, so\r\n% it's easy to follow what he's doing. Let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2521#respond here>.\r\n\r\n##### SOURCE END ##### 810c0da737424631acf48bcfdd7f9c2a\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is fix_lines by Oliver Woodford.\r\n   \r\n   Have you ever generated PostScript files (such as EPS files) from your MATLAB graphs? I had to do that numerous times when\r\n     ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/01\/15\/fixing-postscript-lines\/\">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\/2521"}],"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=2521"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2521\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}