Jagged outline using Matlab 2014b

与世无争的帅哥 提交于 2019-12-18 08:55:59

问题


I am plotting some maps using Matlab that use mapshow to plot the country border from a shapefile. I then export them to both a PDF and EPS format using the export_fig package. This worked completely fine using Matlab 2014a, but I have just upgraded to Matlab 2014b to take advantage of something else that has improved, and now my country border is all jagged. The border only looks jagged on the saved versions of the file. If I zoom in on the figure window, the outline isn't like that.

Here are the snippets of code that are important. It is a custom shapefile, so I don't know how to put it on here so people can replicate it.

This bit reads in the shapefile and plots it. The display type is 'polygon' if that is relevent, hence getting rid of the 'FaceColor' so I can see what I am plotting underneath (the green bits in the background of the images, plotted using pcolor).

thaiborder=shaperead('Thailandborder');
mapshow(thaiborder,'FaceColor','none');

This bit is how I am exporting the figure.

export_fig test.eps -r600 -painters
export_fig test.pdf -r600 -painters

This is the version with a smooth border from Matlab 2014a:

This is roughly the same area of the image, with the jagged border from Matlab 2014b:

Does anyone know why these differences are occurring? I want the border to be like it is in the first image, but I need the "improved" functionality of Matlab 2014b for another thing in the same image. What do I need to change?

Edit to add: I have been in contact with the creator of export_fig and he thinks it is caused by Matlab now using mitred joins rather than round ones. Apparently I have to write to MathWorks to complain. I didn't put this as an answer because someone else may be able to provide a solution for me.


回答1:


Matlab acknowledged that this is known bug. For me the first fix worked.

The issue of jagged lines on the figures while exporting in the vector format is a known bug in MATLAB R2014b. It is associated with the combination of linejoins and meterlimits used in vector format.

To work around this issue, use the attached function fixeps to post process the EPS file. You can use one of the following ways to call this fixeps function.

fixeps('input.eps','output.eps','LJ') % Will change the linejoins to round

fixeps('input.eps','output.eps','ML') % Will correct the miterlimit

function fixeps(inname,outname,fixmode)
if nargin==2
    fixmode = 'LJ';
end
fi = fopen(inname,'r');
fo = fopen(outname,'w');
tline = fgets(fi);
while ischar(tline)
    if (strcmp(tline,['10.0 ML' 10])) % Replace 10.0 miterlimit
        switch (fixmode)
            case 'LJ'
                fwrite(fo,['1 LJ' 10]); % With round linejoin
            case 'ML'
                fwrite(fo,['2.5 ML' 10]); % With smaller miterlimit
        end
    else
        fwrite(fo,tline);
    end
    tline = fgets(fi);
end
fclose(fo);
fclose(fi);



回答2:


I had a similar problem that I found to be caused by the 'MarkerSize' option. It seems that in version 2014b it inherits the units of the figure. For example, if I have a figure in centimeters and I ask for ('MarkerSize', 10), the 10 will not be interpreted as points (as in 2014a) but as cm. I fixed this by changing the figure units to pt.



来源:https://stackoverflow.com/questions/26302938/jagged-outline-using-matlab-2014b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!