Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

plot - Jagged outline using Matlab 2014b

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: 2014a version

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...