- This issue needs to be fixed by MathWorks
- The internal reasons why this happens are not visible to us
Why is vector graphics chopped into pieces?
141 views (last 30 days)
Ilja Maljutenko on 16 Jun 2016
A wise scientist knows, that if they wants their data to be published with best quality then they must publish their figures in PostScript (vector) format.
For Matlab they would need to use 'Painters' render function when exporting their figure (either with print, saveas, export_fig commands). This way the figure becomes independent of resolution (and other benefits concerning line widths and types).
After graphical engine upgrade in Matlab 2014b items on PostScript figures have become fragmented. Patches have become combination of triangles and rectangles and lines have become weakly joint polygons. I can't find a single note about it in update notes -.-
There are many inquiries about mysterious lines appearing on figures:
- ticket #01887614
However proper answer or solution is still absent.
( Editing anti-aliasing settings of PDF viewer ? Seriously? -.- )
Is it a MATLAB issue, or some kind of general PostScript issue? Have this happened with other graphics software also?
Why such "upgrade", which made eps format unusable, was necessary?
What can users do to avoid or fix such poor graphics? (beside switching software)
There is a striking number of earth science (probably also in other fields) papers already published with fragmented "vector graphics" (eg. Article1 , Article2 fig7-8 ,). Not the mentioning increase in size of figure/document/publication that is result of retaining information for each subelement on figure.
See how does your MATLAB handle this issue:
Is it an issue after all?
Stefan Spelitz on 9 Apr 2017
Yes, this problem is all over the internet.
It seems to be an internal Matlab problem, maybe related to their graphics engine HG2. A discussion about this can be found here.
As a workaround I proposed a Matlab script for post-processing .eps files. Of course this does not solve problems with .svg or .pdf files. But .eps files could be manually converted to these formats by using other software (e.g. Illustrator, Inkscape).
Be aware that my tool groups elements according to their properties (e.g. line color, width, ...) which might not be what you want, since two separate lines with the same color might be grouped together in the same layer.
The underlying problem in Matlab seems to be that the exported data is separated into different path elements although logically they should be grouped together. As a result some vector graphics viewers have problems visually merging these clearly separated paths.
As a conclusion:
More Answers (6)
Steve Hansen on 27 Oct 2017
Mathworks proceeded to break their own software three years ago and has done little to respond to the needs of their customers, except for denying the problem and blaming the issue on other people/software.
This issue has been eye opening for me. I used to strongly support Matlab and suggest that everyone use it due to the increased productivity it provided. However, there are very real dangers posed by vendor lock-in, particularly as it applies to science and publishing. Even if it requires more effort, I think open source alternatives are critical for maintaining autonomy.
Pavaman on 11 Oct 2018
Using R2018a, the file sizes are 10 times smaller. However, when converted to pdf, the filesizes are 100 times smaller (comparing to filesizes created in R2016a).
Gerrit Ecke on 19 May 2019
First of all: incredible, Mathworks. You are really trying to sell this as a feature/improvement over the old renderer? If there are oblique borders you render tons of triangles. I am really annoyed, this thing has made my plots ugly for some time now and I have spent ages to fix this thing manually in some cases.
with 2017b the post-processing script doesn't work any more. I found a solution that works for me when I display stuff with contourf. Inkscape (after taking ages to load the 3.5MB svg file MATLAB generates) has the option to select everything of the same color. Hit F2 to enter "edit paths by nodes" mode, select one of the many triangles, right click on it and navigate to "Select Same" --> "Fill Color". The myriads of triangles should be selected now. In the menu bar select "Path" --> "Union". After all paths of the same color are joined you can try "Path" --> "Simplify", for me this usually also works and reduces the number of nodes to a decent number.
Only flaw so far is that sometimes there are additional objects that will also be selected with this method and have to be attended to manually.
Mathworks, please implement a postprocessing in this line for svg export (not based on color I mean of course)!
Evelina Thunell on 15 Dec 2017
Edited: Evelina Thunell on 15 Dec 2017
I exported a matlab figure with a shaded area made with "fill" from matlab, and kept getting line artifacts on the shaded area for vector formats. Very annoying! epsclean did not solve my problem (the artifacts are less pronounced but still there). Then I found this solution:
I did this in Windows 7 with Adobe Illustrator CC 2018 and Matlab 2017a: Save your figure in matlab as a pdf file. Download the stuff from the link above. Open your pdf file in Illustrator and do File-Scripts-Other scripts: pick the file fixMatlabPDFOutput.jsx that you have downloaded. And voila, your artifact pdf is now overwritten by a nice-looking one (and it's still vectorized).
Johannes Kalliauer on 19 Jan 2022
I would recommend to use 'ContentType','vector' of https://de.mathworks.com/help/matlab/ref/exportgraphics.html
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
sphere %plot3(X,Y,Z) %Plot your awesome plot
daspect([1 1 1])%assure that it is not distored
%% Uggly RasterOutput
%% 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
%% 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
print('-depsc','myVectorFile3.eps')%white background which is exeedes the eps-border, not transparent
print('-dpdf','myVectorFile3.pdf')%uggly: has large white borders