MATLAB is not giving good quality eps figure, looks good in png format but looks really bad in pdf.

조회 수: 52 (최근 30일)
I have attached my MATLAB figure MATLAB figure (gdrive), Rendered with Painters. I normally use "saveas" function, to save figure in eps format, to be exact:
saveas(fig, 'myfigure1.eps', 'epsc');
When I use generated eps in overleaf (latex pdf) it looks very bad (seems aliased may be). See the pic below. The peculier red contours are visible. In upper blue region some weird lines like structures appears. In png it looks fine.
Actully it looks better in MATLAB figure, also looks fine in png format. See pic below. I want in eps format.
I used many functions in file exchange but couldn't find a solution. I also ovserved that if I use print command to create pdf directly, even with 6000 dpi the figure looks bad.
Can I have eps of this MATLAB figure with high quality?

답변 (1개)

chicken vector
chicken vector 2023년 6월 14일
편집: chicken vector 2023년 6월 14일
For article/document/presentation images I suggest you to use export_fig from FEX.
The images have a better quality and more saving options (e.g. no white borders).
filepath = 'C:\Users\YourName\Desktop\filename';
export_fig(filepath,'-eps','-transparent','-r300');
  댓글 수: 14
chicken vector
chicken vector 2023년 6월 19일
t's probably connected to the use of the contour function, but this is my guess.
If this is for a paper, .eps figures are in general preferable, but you can also use .pdf or high resolution .png.
Alternatively, you can convert the contour to a surface.
I don't recommend you doing this because produces a large amount of data and heavy figures which makes overleaf copilation much slower, but should work in desprate cases.
close all;
% Input:
resolutionFactor = 10;
% Load data:
fig = open('MatlabQuestion.fig');
ax = fig.Children(3);
cont = findall(ax.Children, 'Type', 'Contour');
% Re-structure:
for j = 1 : length(cont)
cont2surf(ax, cont(j), resolutionFactor);
end
% - [stacking goes here] - %
% Export figure:
export_fig('myfigureR.eps', '-eps', '-r300');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function cont2surf(ax, cont, resolutionFactor)
% Resolution:
xCurrentResolution = length(cont.XData);
yCurrentResolution = length(cont.YData);
xNewResolution = resolutionFactor * xCurrentResolution;
yNewResolution = resolutionFactor * yCurrentResolution;
% function cont2surf(ax, x, y, z)
% Increase data resolution:
xPoints = linspace(1, xCurrentResolution, xNewResolution);
yPoints = linspace(1, yCurrentResolution, yNewResolution);
xInterp = @(n) interp1(1 : xCurrentResolution, cont.XData, n);
yInterp = @(n) interp1(1 : yCurrentResolution, cont.YData, n);
[X,Y] = meshgrid(xInterp(xPoints), yInterp(yPoints));
[x,y] = meshgrid(cont.XData,cont.YData);
Z = interp2(x, y, cont.ZData, X, Y);
% Substitute contour with surface:
delete(cont);
hold on;
surf(X, Y, Z, 'Parent', ax, 'EdgeColor', 'None');
hold off;
view([0 0 1]);
ax.Children = ax.Children(circshift(1 : length(ax.Children), -1));
ax.SortMethod = 'ChildOrder';
end
Remember to change the stack order to display the graphic object as you want.
the stack is accessed through ax.Children and you can change the order as I have done in the function:
%% Example:
% Indeces for new order:
newOrder = randperm(length(ax.Children));
% Setup new order:
ax.Children = ax.Children(newOrder);
% Update stack based on Children order:
ax.SortMethod = 'ChildOrder';

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

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by