Axis font overlaps with axis line following .eps plot export

Good day everyone,
I plot in the following way:
fig = figure('Units','centimeters','PaperSize',[21 29.7], 'Position', [2, 2, 15.59, 8.94]);
ax1=axes;
subplot(1,1,1);
hold on
plot(ax1, Time, Master_I, 'LineWidth',1,'DisplayName','$I_{M}$','Color',"#D95319", LineStyle="-")
plot(ax1, Time, Slave1_I, 'LineWidth',1,'DisplayName','$I_{S1}$','Color',"#0072BD", LineStyle="--")
plot(ax1, Time, Slave2_I, 'LineWidth',1,'DisplayName','$I_{S2}$','Color',"#7E2F8E", LineStyle="--")
plot(ax1, Time, Slave3_I, 'LineWidth',1,'DisplayName','$I_{S3}$','Color',"#77AC30", LineStyle="--")
plot(ax1, Time, Slave4_I, 'LineWidth',1,'DisplayName','$I_{S4}$','Color',"#A2142F", LineStyle="--")
plot(ax1, Time, Slave5_I, 'LineWidth',1,'DisplayName','$I_{S5}$','Color',"#00FFFF", LineStyle="--")
plot(ax1, Time, I_total, 'LineWidth',1,'DisplayName','$I_{tot}$','Color',"k", LineStyle="-.")
ylabel('Current / A', 'Fontsize', 10, 'FontName', 'Latin Modern Roman', 'Interpreter', 'latex')
ylim ([-2.5 2.5])
yticks (-10:0.5:50)
hold off
grid on
xlabel('Time / h', 'Fontsize', 10, 'FontName', 'Latin Modern Roman', 'Interpreter', 'latex')
xlim ([0 6.2])
set (ax1, 'Fontsize', 10, 'FontName', 'Latin Modern Roman', 'YColor', "k", 'Box','on')
legend ('Fontsize', 10, 'FontName', 'Latin Modern Roman', 'NumColumns', 2, 'Interpreter', 'latex');
set(gca,'Box','on')
set(gcf,'renderer','Painters')
set(findall(gcf,'-property','FontSize'),'FontSize',10)
set(findall(gcf,'-property','FontName'),'FontName','Latin Modern Roman')
set(findall(gcf,'-property','Interpreter'),'Interpreter','latex')
Once in the plot window I save the plot (File --> Save As..), I obtain the following as .eps (left) and as .png (rigth):
My problem is that the axis numbering overlap with the y-axis line in .eps, and this seems to be related to the export in this particular format which I need :( Any suggestion?
Thank you for taking your time to read and understad.

 Accepted Answer

Thanks for sharing @Totilo. The problem is with the font, Latin Modern Roman. When I change the font to Arial, for example, the eps version of your figure looks fine.
A workaround is to add some space to the right of the axis ticks. One way to do that is set the yticklabel.
ax1.YTickLabel = compose ('%g ', ax1.YTick);
or
ax1.YTickLabel = compose ('%.1f ', ax1.YTick)
depending on your preferences.
Additional feedback
  1. You don't need ax1=axes;and subplot(1,1,1); I suggest removing subplot
  2. If you're using MATLAB R2022a or later, instead of using set(findall(gcf,'-property',... to set fontsize and fontname, use the new fontsize and fontname functions. However, since you're setting the interpreter to latex, setting fontname and fontsize may not have the affect you intend.

2 Comments

Thank you. Both workarounds produce usable results. In case someone else looks for it, here the eps exports: left with '%g ' and right with '%.1f '
Thanks again.
I did some more digging and found out that the issue is with the use of Latin Modern Roman font. When I generated your figure using different fonts, the eps looked fine.

Sign in to comment.

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 8 Jun 2023

Commented:

on 9 Jun 2023

Community Treasure Hunt

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

Start Hunting!