How to Output Accurate PDF from Matlab figure
조회 수: 30 (최근 30일)
이전 댓글 표시
Hi everyone:
For some reason, I need to plot the mask of a microfluid device in Matlab, which consists of many posts separated by certain distance The plotting process is easy but when I tried to 'print' it into PDF file, the image was distorted (circles are not round, and they have obvious defect on them), and the spacing was not right(shortened).
I've tried function 'rectangle', code like:
function drawFilledCircle (center_x, center_y, radius)
%%Draw a filled circle
xc = center_x; yc = center_y;
r = radius;
x = r*sin(-pi:0.01*pi:pi) + xc;
y = r*cos(-pi:0.01*pi:pi) + yc;
fill(x, y, [0,0,0]);
and even a function called 'filledCircle' which I found on fileexchange.
But I always got the wrong thing. I don't know what I can do to fix it.
Please help.
P.S. I attached the original matlab figure and the printed PDF for references.
P.S.2 I've also tried to output them into other formats like EPS, but even EPS doesn't look right.
댓글 수: 4
lvn
2014년 3월 19일
Could you post the complete code that would reproduce test.fig? I would like to see if I manage to export it correctly.
채택된 답변
lvn
2014년 3월 20일
The problem with the spacing is in fact a problem of the line around the circle. Because you work on such small scales, it determines the size of the circle! This solves it I think. In your code change the rectangle functions to
rectangle('position',[position_x + index*(diameter + distance), position_y, diameter, diameter],'curvature',[1,1],'FaceColor',[0,0,0],'LineStyle','none');
and then Jan Simon's export print(gcf, 'test.eps', '-dpsc2', '-r1200', '-noui').
After conversion to pdf, the result looks ok to me (see attached).
댓글 수: 3
추가 답변 (4개)
Chad Greene
2014년 3월 18일
I highly recommend switching to export_fig instead of using print. Here's export_fig: http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
Oliver Woodford, the author of export_fig has a quite helpful and succinct site with plenty of picture examples and troubleshooting tips here: https://sites.google.com/site/oliverwoodford/software/export_fig
Does the attached pdf look correct?
Chad Greene
2014년 3월 18일
Oh, interesting. I see the problem now, but is this a pdf issue, or an issue with the filled circle function? Perhaps simply creating a scatter plot and setting the size of the markers would fix it? http://www.mathworks.com/matlabcentral/answers/101738
Chad Greene
2014년 3월 19일
Frank,
Follow the circles command with axis equal to ensure the circles don't get squashed.
댓글 수: 2
Jan
2014년 3월 19일
This creates a perfectly looking EPS and after a conversion the resulting PDF is fine also:
print(gcf, 'test.eps', '-dpsc2', '-r1200', '-noui')
Increasing the resolution to 1200 makes the difference.
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!