figure export in epsc-file produce artefacts

Hello Community,
the LineStyle of the figure and the exported "eps-File" are different.
Is this a bug in the eps-export routine?
When i export it as png-file everything is fine.
Best regards
emjay
function batteryModel_test()
U = 3.7; % V
Ri = 1e-3; % Ohm
mBat = 1; % kg
eBat = 200*3600; % Ws/kg
EBat = mBat*eBat; % Ws
cpBat = 1000; % J/kg/K
deltaT = 10; % K
ETher= cpBat*mBat*deltaT; % J
RLast = Ri:Ri/10:1; % Ohm
r = RLast/Ri;
I = U./(Ri+RLast);
PLoss = Ri.*I.^2;
PLast = RLast.*I.^2;
PBat = PLoss+PLast;
plotSubplot(r, I, PBat, PLoss, PLast, ETher, EBat);
end
function plotSubplot(r, I, PBat, PLoss, PLast, ETher, EBat)
figure(1)
clf
set(gcf, 'Position', [100 100 600 500]);
% Subplot 1: Power curves
subplot(3,2,[1 3])
hold on
loglog(r,PBat ,'k' ,'Linewidth',2)
loglog(r,PLoss,'k-.','Linewidth',2)
loglog(r,PLast,'k--','Linewidth',2)
xline(68,'k','HandleVisibility','off')
legend('P_{Bat}','P_{Loss}','P_{Load}','Location','southwest')
set(gca,'XScale','log', 'YScale','log')
ylabel('Power [W]')
grid on
box on
% Subplot 2: Current vs. r
subplot(3,2,[2 4])
plot(r,I,'k','LineWidth',2)
xline(68,'k','HandleVisibility','off')
ylabel('Current [A]')
set(gca,'XScale','log', 'YScale','log')
grid on
box on
ylim(10.^[0 4])
% Subplot 3: Battery efficiency
subplot(3,2,5)
plot(r, PLast./PBat*100,'k','LineWidth',2)
xlabel('R_{Load} / R_i')
ylabel('\eta_{Bat} [%]')
set(gca,'XScale','log')
xline(68,'k','HandleVisibility','off')
grid on
box on
% Subplot 4: Time calculations
subplot(3,2,6)
hold on
plot(r, (ETher./PLoss)/3600, 'k','LineWidth',2)
plot(r, (EBat./PBat)/3600, 'k-.','LineWidth',2)
plot(r, 3600./(EBat./PBat), 'k--','LineWidth',2)
xline(68,'k','HandleVisibility','off')
xlabel('R_{Load} / R_i')
ylabel('time [hr]')
legend('t_{therm}', 't_{elec}', 'C_{rate}', 'Location', 'southeast')
set(gca,'XScale','log', 'YScale','log')
grid on
box on
ylim(10.^[-4 3])
saveas(gcf, 'batteryModel', 'epsc')
saveas(gcf, 'batteryModel', 'png')
end

Answers (1)

Hi Marko,
The line styles may appear different for both formats, especially in the case of the "Dash-dotted line" for P_Loss, but they are indeed the same for both formats.
This visual difference occurs due to the nature of the file being vector graphics in the case of EPSC and a raster image in the case of PNG. Adding to the discrepancy, the saveas function uses a lower resolution of 150 DPI for PNG files.
To obtain an image closer to the EPS format vector graphics, consider using the exportgraphics function, which allows for an increase in the resolution of the PNG image.
exportgraphics(gcf, 'batteryModel.png', 'Resolution',600)
For more information on the exportgraphics function, please refer to the following documentation: https://www.mathworks.com/help/matlab/ref/exportgraphics.html

4 Comments

Hello Epsilon,
ok so there is no soltion for vector graphics.
I tried the exportfunction as *.eps and as *.pdf but the exported files has the same issues.
Hi,
I see the same linetype in the *.eps and *.pdf files as the figure.
Screenshot from pdf file:
Screenshot of Figure Window:
Can you pin point the issue in the *.eps and *.pdf files by taking a screenshot and attaching it here?
When i open the eps file on my mac:
it looks like mac's preview.app can't display it correctly.
I found a recent article from apple stating that macOS no longer includes built-in support for viewing PostScript (.ps) and Encapsulated PostScript (.eps) files. https://support.apple.com/en-us/108775

Sign in to comment.

Categories

Products

Release

R2023b

Asked:

on 20 Mar 2025

Commented:

on 26 Mar 2025

Community Treasure Hunt

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

Start Hunting!