Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
935 views
in Technique[技术] by (71.8m points)

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

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

enter image description hereenter image description here (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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)Inkscapeinkscape.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'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...