MATLAB is not giving good quality eps figure, looks good in png format but looks really bad in pdf.
Ältere Kommentare anzeigen
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?
Antworten (1)
chicken vector
am 14 Jun. 2023
Bearbeitet: chicken vector
am 14 Jun. 2023
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 Kommentare
JAY PATEL
am 14 Jun. 2023
chicken vector
am 14 Jun. 2023
This never occured to me so it's hard to tell without looking at the figure data.
Have you tried to save directly in .pdf with export_fig?
JAY PATEL
am 14 Jun. 2023
chicken vector
am 14 Jun. 2023
For me both .eps and .pdf work fine.
Did you download ghostscript and xpdreader?
chicken vector
am 14 Jun. 2023
I don't see your problem even if I use Matlab's saveas.

JAY PATEL
am 15 Jun. 2023
chicken vector
am 15 Jun. 2023
Bearbeitet: chicken vector
am 15 Jun. 2023
ghostscript and xpdftool are external tools used by export_fig.
You can use one of these three to remove the background:
fig = open('MatlabQuestion.fig');
% Method 1:
export_fig('myfigure1', '-eps', '-transparent');
% Method 2:
exportgraphics(fig, 'myfigure2.eps', 'BackgroundColor', 'None', 'ContentType', 'Vector')
% Method 3:
ax = findall(fig, 'Type', 'Axes');
set(ax, 'Color', 'None');
saveas(fig, 'myfigure3.eps', 'epsc');
I suggest you to use Method 1 because from my tests is the only one that does not create aliasing lines.
JAY PATEL
am 15 Jun. 2023
chicken vector
am 15 Jun. 2023
Bearbeitet: chicken vector
am 15 Jun. 2023
Weird. It has been a while I did not use the transparent option, but i don't remember this behaviour.
You can use the same approach from previous answers:
fig = open('MatlabQuestion.fig');
set(gca, 'Color', 'None');
export_fig('myfigure1', '-eps');
chicken vector
am 15 Jun. 2023
My bad I changing the axes rather than teh figure;
You can use this:
set(fig, 'Color', 'w');
I think the black background come from the fact that;
set(fig, 'Color', 'None');
Sets the background to black.
JAY PATEL
am 16 Jun. 2023
chicken vector
am 19 Jun. 2023
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';
JAY PATEL
am 20 Jun. 2023
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





