Hard contour using Matlab 2014b
I am drawing some maps using Matlab which is used mapshow
to plot the country border from a shapefile. Then I export them to PDF and EPS using the package export_fig
. This worked completely using Matlab 2014a, but I just upgraded to Matlab 2014b to take advantage of something else that has improved and now my country border is all jagged. The border is only visible in saved versions of the file. If I zoom in in the drawing window, the outline doesn't look like it.
Here are the code snippets that are important. This is a custom shapefile, so I don't know how to enable it so people can replicate it.
This bit is read in the shapefile and displays it. The display type is "polygon" if relevant, so getting rid of 'FaceColor'
, so I can see what I am drawing at the bottom (green bits on the background of the images, built using pcolor
).
thaiborder=shaperead('Thailandborder');
mapshow(thaiborder,'FaceColor','none');
This bit is how I export the shape.
export_fig test.eps -r600 -painters
export_fig test.pdf -r600 -painters
This is the smooth border version from Matlab 2014a:
This is roughly the same image area, with a jagged border from Matlab 2014b:
Does anyone know why these differences are happening? I want the border to be the same as 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 was in contact with the creator export_fig
and he thinks this is because Matlab is now using mitred and not round ones. Apparently I have to write to MathWorks to complain. I did not put this as an answer because someone else might provide me with a solution.
source to share
Matlab has acknowledged that this is a known bug. For me, the first fix worked.
The issue with jagged lines in figures when exporting to vector format is a known bug in MATLAB R2014b. It is associated with a combination of strings and symbols used in vector format.
To work around this issue, use the included fixeps function to publish the EPS file process. You can use one of the following ways to call this fixeps function.
fixeps ('input.eps', 'output.eps', 'LJ')% Will change linejoins to round
fixeps ('input.eps', 'output.eps', 'ML')% The miterlimit value will be fixed
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);
source to share
I had a similar problem that I thought was caused by the "MarkerSize" parameter. It looks like in version 2014b it inherits the units of the shape. For example, if I have a number in centimeters and I ask for ("MarkerSize", 10), then 10 will not be interpreted as dots (as in 2014a), but as cm. I fixed this by changing the shape units to pt.
source to share