Why is vector graphics chopped into pieces?
Show older comments
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:
- http://se.mathworks.com/matlabcentral/answers/162257-problem-with-patch-graphics-in-2014b-splits-in-two-along-diagonal
- http://se.mathworks.com/matlabcentral/answers/16295-figure-export-to-eps
- https://github.com/altmany/export_fig/issues/44
- http://stackoverflow.com/questions/29824739/matlab-edges-of-patches-visible-after-export-as-vector-graphics
- ticket #01887614
However proper answer or solution is still absent.
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:
contourf(peaks(100));saveas(gcf,'figure.eps','epsc')
Is it an issue after all?
7 Comments
Ilja Maljutenko
on 6 Sep 2016
Dene Farrell
on 20 Dec 2016
Edited: Dene Farrell
on 20 Dec 2016
Here is a hack fix that uses Illustrator programmatically to fix Matlab's output by uniting fractured paths of the same color. I don't think there is anyway to fully deal with this problem from outside of Mathworks core code.
Stefan Spelitz
on 3 Mar 2017
I provided a Matlab script to fix EPS files generated by Matlab R2016b:
It fixes both:
- The split-up of paths by re-combining them
- White line artifacts
Ilja Maljutenko
on 31 Mar 2017
Stefan Spelitz
on 31 Mar 2017
Ilja,
true - it is only a grouping. But by doing so at least some of the graphical glitches are resolved (see examples in my github project). If you have some Matlab code for output graphics which cannot be repaired I would like to have a look, maybe it can be improved.
Ilja Maljutenko
on 5 Apr 2017
Oskar
on 2 Jun 2017
Yes, this is a major issue. Anyone who has more information about the issue; is a solution from MathWorks coming soon, or is it not a prioritized matter?
Anyway, thanks for the work-arounds! Especially, the epsclean function which I find very useful. Thanks!
Accepted Answer
More Answers (7)
Steve Hansen
on 27 Oct 2017
3 votes
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
1 vote
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
1 vote
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)!
Cheers.
5 Comments
Gerrit Ecke
on 19 May 2019
PS:
saveas(gcf,'figure.eps','epsc') on 2017b gives me the contourf plot as four png images, separated by the white lines that are topic of this thread.
Preetish Kakkar
on 19 May 2019
Gerrit, we have made tremendous progress in fixing these issue, we request you to try 19a in which we believe you should very minimal white line issues. Please let me know if you find any specific issues after trying it in 19a.
Ilja Maljutenko
on 19 May 2019
Edited: Ilja Maljutenko
on 19 May 2019
Preetish Kakkar
on 20 May 2019
@llja, can you give me an example of what you are referring for contour lines, what issues are you facing with contour lines? Please give an example of contour I can try it with.
Gerrit Ecke
on 21 May 2019
Dear all,
apologies for my bad tamper in my original e-mail. I know how it is with these things. However, I feel that this particular issue should have high priority, given the price of the product.
Same experience like Ilja: I have also once re-rendered heat plots generically as pixel graphics and combined it with custom vector graphic outline on top. I think it was a Robinson projection. This would be an adequate general solution in my opinion, however, my code was not general enough, I am afraid.
I do not have the opportunity to try the latest Matlab release, unfortunately. I am not sure whether I understand Ilja right that the problems in contourf are already fixed. If not, I think my solution is very easy and quick to implement. I guess the individually colored panels, i.e. the surfaces between contour lines, have separate representations internally. The "union" opreation here would be sth. like the hull of all nodes of this object.
Evelina Thunell
on 15 Dec 2017
Edited: Evelina Thunell
on 15 Dec 2017
0 votes
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:
https://github.com/dfarrel1/fix_matlab_vector_graphics
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).
Preetish Kakkar
on 7 Apr 2018
Edited: Preetish Kakkar
on 7 Apr 2018
0 votes
I think this shall be working (for e.g. contourf(peaks(100));saveas(gcf,'figure.eps','epsc') ) starting from 17b. The example I gave shall not produce white line.
3 Comments
Pavaman
on 11 Oct 2018
You're saying these painters rendering issues are fixed?
Preetish Kakkar
on 11 Oct 2018
Yes, I won't say every painter issue is fixed but we have made considerable progress on not producing white line in some cases such as contourf example I gave above. I would recommend trying latest matlab release and report any issues you find. We are diligently working on improving the quality and we expect more fixes to come in upcoming releases.
Ilja Maljutenko
on 11 Oct 2018
Johannes Kalliauer
on 19 Jan 2022
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
Alex Dorn
on 10 Aug 2023
0 votes
For me the following workaround fixed the artefact issue:
I plotted a surface via the mesh() function. Then opened the property editor of the mesh in the current axes and edited the EdgeColor property and set it to 'none',
Next, Changed the property FaceColor of the mesh to 'Interp'.
Finnaly, I set the Renderer property of the figure to 'painters' and that's it!
When now exporting the figure as a svg file the artefacts are gone and you have still a vector graphic.
I hope that work out for all of you.
I was using R2022b
Cheers
Alexei
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!