Why does MATLAB not export EPS files properly?
130 次查看(过去 30 天)
显示 更早的评论
Also, when I generate EPS files from MATLAB, I seem to be getting unusually large files that are displaced to the bottom left hand side of your image, leaving a large white border on two sides. Sometimes the files appear tiled.
采纳的回答
MathWorks Support Team
2013-4-26
This behavior is most likely due to the renderer.
The renderer that MATLAB is using to display the images is very likely a bitmap renderer such as OpenGL or zbuffer (the figures you sent me used the ‘zbuffer’ renderer). EPS formats are essentially vector formats so it is best if the renderer that you use to generate the figure is also a vector renderer ('painters').
As you are likely using a bitmap renderer, MATLAB has to first convert the bitmap into a vector, and this conversion of bitmaps to vector images is often a time-consuming and inefficient process.
This is why your images appear incorrect when you print them.
SOLUTION:
1) Change the renderer of the figure before you draw your figure or before you export. You can use the following command:
>>set(gcf,'renderer','Painters')
2) Change the renderer used by the PRINT command. By default it uses the same renderer that the figure uses, so you would have to type the following command to over-ride this:
>> print -depsc -tiff -r300 -painters <filename>.eps
or
>> print -depsc2 -tiff -r300 -painters <filename>.eps
Also, I suggest you use a PostScript printer or viewer to view your EPS files. This is just to make sure that you are viewing your actual EPS file and not the TIFF preview.
0 个评论
更多回答(1 个)
Johannes Kalliauer
2022-1-19
I would recommend to use 'ContentType','vector' of https://de.mathworks.com/help/matlab/ref/exportgraphics.html
%EPS
exportgraphics(gcf,'myVectorFile.eps','BackgroundColor','none','ContentType','vector')
%PDF
exportgraphics(gcf,'myVectorFile.pdf','BackgroundColor','none','ContentType','vector')
an example:
clear
close all
warning('off','MATLAB:print:ContentTypeImageSuggested')%turn of Warning that it Vectorgraphics might be slow compared to raster, the difference is less than 10% for this example
gcf=figure(314159265);
sphere %plot3(X,Y,Z) %Plot your awesome plot
daspect([1 1 1])%assure that it is not distored
%% Uggly RasterOutput
disp('Rasterouptut')
print('-depsc','-tiff','-r300','UgglyRaster.eps')%uggly: Rastergraphics
print('-dpdf','UgglyRaster.pdf')%uggly: Rastergraphics
%% Vector Output1 (no border for PDF, and optional transparent background)
disp('exportgraphics')%for R2020a or newer https://de.mathworks.com/help/matlab/ref/exportgraphics.html
exportgraphics(gcf,'myVectorFile1.eps','BackgroundColor','none','ContentType','vector')
exportgraphics(gcf,'myVectorFile1.pdf','BackgroundColor','none','ContentType','vector')
%% Vector Output2
disp('-vector')%In R2022a -painters got replaced by -vector
print('-depsc','-tiff','-r300', '-painters','myVectorFile2.eps')%large filesize
print('-dpdf','-r300', '-painters','myVectorFile2.pdf')%uggly: has large white borders
%% Vector Ouptut3
disp('Painters') %https://www.mathworks.com/matlabcentral/answers/92521-why-does-matlab-not-export-eps-files-properly
set(gcf,'renderer','Painters')
print('-depsc','myVectorFile3.eps')%white background which is exeedes the eps-border, not transparent
print('-dpdf','myVectorFile3.pdf')%uggly: has large white borders
Best Regards
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!