{"id":993,"date":"2018-12-15T19:57:16","date_gmt":"2018-12-16T00:57:16","guid":{"rendered":"http:\/\/www.hargaden.com\/enda\/?p=993"},"modified":"2021-04-15T13:08:31","modified_gmt":"2021-04-15T13:08:31","slug":"different-fonts-for-matlab-plots-exported-to-pdf","status":"publish","type":"post","link":"https:\/\/hargaden.com\/enda\/different-fonts-for-matlab-plots-exported-to-pdf\/","title":{"rendered":"Different fonts for Matlab plots exported to PDF"},"content":{"rendered":"<p>When exporting graphics from Stata or Matlab, it&#8217;s better to select a lossless\/vectorized format instead of a rasterized pic. This ensures your image is high-quality and not grainy\/pixelated.<\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"width: 200px;\"><img decoding=\"async\" class=\"aligncenter\" src=\"\/enda\/wp-content\/gross.PNG\" alt=\"Grainy exports\" width=\"180px\" \/><\/p>\n<p style=\"text-align: center;\">Poor quality, grainy image<\/p>\n<\/td>\n<td style=\"width: 200px;\"><img decoding=\"async\" class=\"aligncenter\" src=\"\/enda\/wp-content\/better.PNG\" width=\"180px\" \/><\/p>\n<p style=\"text-align: center;\">Better quality export<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Unfortunately, Matlab does not allow lossless PDF exports of pictures with non-standard fonts. (I&#8217;m not the first person to <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/answers\/23511-save-a-figure-to-pdf-or-eps-with-non-standard-fonts\">notice this problem<\/a>. I failed to implement Juan Guerrero&#8217;s suggested solution.) Matlab will export the font in PNG no problem, but your image will appear grainy. If you try to export as a PDF, your fonts will be reverted to something weird. Obviously this doesn&#8217;t matter if you&#8217;re happy with the default fonts, but this bug does limit your ability to customize the output.<\/p>\n<p>Thankfully, with the help of the nice people at Inkscape (https:\/\/inkscape.org\/) there is a workaround.<\/p>\n<ol>\n<li>Install Inkscape<\/li>\n<li>Generate your figure in Matlab<\/li>\n<li>In &#8220;Export Setup&#8221;, change the Font to anything saved on your system. Export as Scalable Vector Graphic (SVG) file<\/li>\n<li>Open the SVG in Inkscape<\/li>\n<li>Save it a lossless PDF as, say, figure7.pdf<\/li>\n<li>Include in your LaTeX document with \\includegraphics{figure7}<\/li>\n<\/ol>\n<p>Done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When exporting graphics from Stata or Matlab, it&#8217;s better to select a lossless\/vectorized format instead of a rasterized pic. This ensures your image is high-quality and not grainy\/pixelated. Poor quality, grainy image Better quality export&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,8],"tags":[],"class_list":["post-993","post","type-post","status-publish","format-standard","hentry","category-economics","category-latex"],"_links":{"self":[{"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/posts\/993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/comments?post=993"}],"version-history":[{"count":1,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/posts\/993\/revisions"}],"predecessor-version":[{"id":1103,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/posts\/993\/revisions\/1103"}],"wp:attachment":[{"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/media?parent=993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/categories?post=993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hargaden.com\/enda\/wp-json\/wp\/v2\/tags?post=993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}