Exporting figures as vector graphics in .pdf-format using HG2-Update and 'painters' renderer is not working properly

萝らか妹 提交于 2019-11-28 05:18:36

问题


I'm using the still undocumented HG2-Update to create my MATLAB plots, because they just look that much nicer.

(Source: Yair Altman)

Actually, using the current version Release 2013b it works quite nicely and there are not much issues. Except one wants to export the figures as vector graphics (renderer: '-painters'), especially as pdf.

I use the commands:

saveas(gcf,'test.pdf','pdf')

or

print(gcf,'test.pdf','-dpdf')

There are rendering issues, the print does not contain the whole figure and some parts are cropped or non-default fonts are not recognized.

But I'd really like to stay with HG2 and I'd still like to use vector graphics. Is there any solution or workaround?


回答1:


Exporting vector graphics using the yet not official HG2-Update is quite an issue. The .pdf-export is still totally screwed up. What is working fine is the .svg-export, apart from that the boundary box is not set properly.

The long workaround would be: Save the plot with '-dsvg' (print-command) or 'svg' (saveas-command) as vector graphic, open the file in the open source application Inkscape and save again as .pdf with the Export area is drawing checkmark set.

Quite complicated, so I found a way to do it via command-line directly from Matlab (Inkscape still required!):

filename = 'test';
inkscapepath = '"C:\Program Files (x86)\Inkscape\inkscape.exe"';

%// save as .svg
saveas(gcf,filename,'svg')
%// open and save with "export-area-drawing" set via command line
system( [inkscapepath ' ' filename ...
         '.svg --export-area-drawing --export-pdf=' filename '.pdf'])

It takes some time, but works without any known issues for now.

Additionally delete the svg-File afterwards:

delete([filename '.svg'])



回答2:


I had the same problem and used the workaround from thewaywewalk. Now I discovered the MATLAB function "hgexport" works under HG2 (in R2014a).

An issue still was the paper size. I want to use the same size for all graphs with as little white frame as possible. Here you have to set two sizes:

The papersize is set with set(gcf,'PaperSize',[width height]) and the size of your chart is set through export styles. These are set in "Export Setup" or command line:

exp_style=hgexport('readstyle','default');
exp_style.Width = 'width';
exp_style.Height = 'height';
exp_style.Renderer = 'painters';

Now you can export your pdf:

hgexport(gcf,'pdfname',exp_style,'Format','pdf');

PS: In HG2 you may also use Latex for tick labels:

set(gca,'TickLabelInterpreter','latex');


来源:https://stackoverflow.com/questions/25229045/exporting-figures-as-vector-graphics-in-pdf-format-using-hg2-update-and-painte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!