Clean/Repair .eps PostScript vector graphic files created by Matlab R2016b and Matlab R2017a. (Not working with R2017b and later versions (yet)).
- Paths are grouped together according to their properties
- White line artifacts are fixed
- Broken up polylines are connected back together if they share the same properties (good for post-processing in Illustrator/Inkscape/etc.)
- Adjacent polygons of the same type are merged together (use parameter 'combineAreas')
- Why is vector graphics chopped into pieces?
- Lines on Patch-Objects after *.EPS/PDF export - e.g. with contourf
Here is an example of what the .eps file looks before and after fixing it:
%%% Matlab Code
z = peaks;
contourf(z);
print(gcf,'-depsc','-painters','out.eps');
epsclean('out.eps'); % cleans and overwrites the input file
Layer count in Adobe Illustrator: 789 (before) vs. 30 (after)
%%% Matlab Code
[X,Y,Z] = peaks(100);
[~,ch] = contourf(X,Y,Z);
ch.LineStyle = 'none';
ch.LevelStep = ch.LevelStep/10;
colormap('hot')
saveas(gcf, 'out.eps', 'epsc');
epsclean('out.eps'); % cleans and overwrites the input file
Layer count in Adobe Illustrator: 11,775 (before) vs. 76 (after)
- If you experience Z-order problems (i.e. the overlappings of your graphics change) try using parameter 'groupSoft' = true.
%%% Matlab Code
epsclean('out.eps','groupSoft',true);
- If you have separating lines between filled areas (example - gaps highlighted in yellow) try using parameter 'closeGaps' = true.
%%% Matlab Code
epsclean('out.eps','closeGaps',true);
- Have a look at the tests/cleantest.m script for test cases and examples
- Report any problems here at github with your examples (code or .eps file). I try my best to fix them