R2014b tesselates contour plots when saving to eps

When saving a contour plot to a vector format, the eps vector plot is "tesselated", i.e. it has dense triangular divisions along the fill of the contour.
This problem can be reproduced by
Z=peaks(50);
contourf(Z);
print(gcf,'-depsc','-painters','contours.eps');
Most viewers will show a white grid cut into many triangles on the figure. The file size is also very large (i.e. 532 KB vs 27 KB on previous versions). This makes a vector export of filled regions nearly useless in R2014b.
Running the same commands on previous versions results in a figure without tesselation. My operating system is OSX Yosemite 10.10.1.

댓글 수: 1

In my work I rely heavily on contour map plots. Since version 2014b I cannot create publication quality vector figures anymore. The filled contours will have visible dividing lines on screen and on paper. So I use MATLAB 2014a, as it is the last version of MATLAB that works for me. What a pity!

댓글을 달려면 로그인하십시오.

답변 (5개)

Moises Jezzini
Moises Jezzini 2017년 1월 13일
As today, the problem persist. This is one more workaround option.
The idea is to save all vectorial elements in an svg, and the colormap in a bitmap (in this case png). Then use Inkscape to fit the svg with the png.
Z = peaks(20);
hold on;
[~, hcf] = contourf(Z, 100, 'LineColor', 'none');
shading interp;
[~, hc] = contour(Z, 'ShowText','on', 'LineColor', 'black');
title('An example');
hold off;
set(hcf, 'Fill', 'off'); % Removes the contourf
print('Vector', '-dsvg'); % Saves the svg
set(hcf, 'Fill', 'on'); % Shows again the coutourf
set(hc, 'Visible', 'off'); % Hides the coutour lines
% When turning off the axis, the dimensions of the plot will change
% We will save the dimensions to perserve them
OriginalPosition = get(gca, 'Position'); % Save dimensions
axis off;
% Next lines to remove title
h_ch = get(gcf,'Children');
h_str = get(h_ch, 'Title');
set(h_str, 'String',''); % Remove title
set(gca, 'Position', OriginalPosition); % Now reset the plot dimensions
print('Bitmap', '-dpng');
Now, you need to open the svg file in Inkscape (free and open source). Select all (Ctrl-A), ungroup (Ctrl-U) and remove the backgrounds. Then import the png (File->Import), send it to the back (End), then you will need to fit the sizes and align. In this way the background is a bitmap and the numbers, axis and lines are vectors.
Dene Farrell
Dene Farrell 2016년 12월 21일
편집: Dene Farrell 2016년 12월 22일

1 개 추천

Previously Answered Here.
[Basically it says: Another work around is to use illustrator programatically fix_matlab_vector_graphics]
Mathworks have been answering these inquiries with excuses that it's an 'antialiasing algorithm' bug in the viewer and that the new export is better because it's simpler to break up these vector graphics into subcomponents. I'm really confused as to how they can convince themselves that this is true and how they convince others.
It's not acceptable for paid, proprietary software to make huge mistakes like this and then falsely blame it on an anti aliasing algorithm. Mathworks, you need to treat your paying customers with more respect! We are almost 6 versions past the original problem and they still haven't fixed it (2014b - 2017a).

댓글 수: 2

Jan Simon does not work for Mathworks.
Okay, thanks, I updated the post.

댓글을 달려면 로그인하십시오.

Mike Garrity
Mike Garrity 2015년 1월 6일

0 개 추천

We've been discussing that change in the comments section of this question .
It was done to avoid problems we were seeing with downstream apps choking on very complex polygons. We've probably dialed it too far in that direction. We'll probably move it back towards less subdivision than R2014b, but not as far as earlier releases.

댓글 수: 4

Thanks for the details Mike. It's great to know that the problem is being worked on.
Meanwhile, is there any known workaround? So far, I need to revert back to a old version of MATLAB to get useable contour plots. Using Illustrator, I haven't encountered any problems with the previous painters output, even though the contours can be quite complex.
I don't think that there's a simple way to put Humpty-Dumpty back together once he's been subdivided.
And yes, Illustrator is one of the better apps at handling complex polys. But the easiest way to encounter the buggy cases with contourf is to start using XData & YData to define grids which have self intersections, like this example .
I really hope you can bring in an option to get rid of the subdivisions, because the way it is now creates a problem for people using software such as Illustrator. I am seeing a 25-fold increase in my .eps file sizes, to the point that they are completely intractable in Illustrator.
Dividing a vector patch into a discrete number of uniform triangles completely defeats the point of saving a vector image, as it is now essentially a (very poor and inefficient) bitmap.
I agree with Ben, the subdivisions make the vector image very difficult to process with editing tools such as Illustrator. There are a number of other annoyances introduced in R2104b that I do hope gets fixed. For example, axis tick labels are now (somewhat arbitrarily) grouped together in the same text box. If I change the font size on the labels, they now lose their positions relative to the markers. These details are crucial for the many who use MATLAB to produce scientific figures.

댓글을 달려면 로그인하십시오.

Michael S
Michael S 2015년 5월 21일
편집: Michael S 2015년 5월 21일

0 개 추천

One (slightly complicated) workaround:
  • use contour (not contourf)
  • save as eps / pdf (the latter is even better for me since the objects are grouped better than in the eps case - at least in Illustrator)
  • now you have your contour-lines as hundreds of small line segments (i guess also one effect of the mentioned tesselation problem, in older Matlab versions this worked better)
  • but you can select all the lines from one contour and join them. Now you can nicely change their appearance and also fill them to get something like a contourf plot (of course this is very complicated if you have a complex contour-landscape ... but in my case it was feasible)
I discovered that these contour lines have various export appearances for different OS and Matlab/Illustrator versions. I use pdf export and have R2014b + Illustrator CS5 on Windows7. On our Mac with R2012b we use eps export.

댓글 수: 2

Good suggestion!
I think that you'll find that it joins the line segments if you set the contour's LineStyle to something other than solid. The reason is that there's a performance cost to joining them, we skip that when we don't think it's going to matter.
So try creating your contour with a different LineStyle, then after you export it, set it back to solid in Illustrator.
Nice workaround, thanks for sharing!
It would be difficult for my case because my figure has a very large number of contours. Here's an example:
Prior to this change, contourf() produces much nicer looking images than plotting individual pixels with image(), especially if there are not too many sample points.

댓글을 달려면 로그인하십시오.

John Ho
John Ho 2016년 12월 22일
편집: John Ho 2016년 12월 22일

0 개 추천

Thank you @Dene Farrell for revisiting this issue.
The previous answer by @Mike Garrity was accepted based on the implied promise that the issue would be fixed in future versions of MATLAB. Almost two years and 6 versions later, it has not. Meanwhile, researchers and engineers that rely on MATLAB to generate publication-quality vector graphics have had to rely on workarounds. The fix could be as simple as putting an option in the export that reverts to the previous function - I have had no problems with the eps export function in the past, and the decision to split into subpolygons is damaging and mystifying. The vector graphics support has become significantly worse after R2014b for almost every common eps task (circle markers are practically hexagonal!?!) and it is unacceptable that no effort has been made to fix this.

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2015년 1월 6일

답변:

2017년 1월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by