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.

 채택된 답변

Adam Danz
Adam Danz 2023년 6월 8일
편집: Adam Danz 2023년 6월 9일
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

Totilo
Totilo 2023년 6월 8일
편집: Totilo 2023년 6월 8일
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.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 6월 8일

댓글:

2023년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by