我试图导出一个Matlab图形作为PDF矢量图使用Matlab的“导出图形”功能,如Matlab文档中的建议。关于参考资料,见:
https://www.mathworks.com/help/matlab/ref/exportgraphics.html
一切都很好。但是,用于标题、x和y标签的字体和滴答号与在运行代码后弹出的Matlab图形中使用的字体不匹配。它更改为字体“时间”,不符合我的目的。现在我想指定这三种字体的字体:标题,x和y标签,和滴答(数字)。单独这样做不是必要的,而是可选的。有人有什么建议吗?
正如您在我的代码中所看到的,我已经尝试通过在(例如)中指定字体来影响字体。"ylabel“命令。
figure
plot(Zeit1,Temperatur1,'LineWidth',2)
grid on
title('Temperatur-Messprogramm für Messreihe 1')
xlabel('Zeit [min]')
ylabel('Temperatur [°C]', 'FontName', 'Helvetica')
xlim([-5 150])
ylim([-5 405])
set(gca,'FontSize',30)
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_1.jpg','Resolution',600)
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_1.pdf','Resolution',600,'ContentType','vector')
这确实会影响Matlab图形中显示的字体,但是对以编程方式导出的PDF矢量图形没有任何改变。无论我做什么,这个字体都保持在"Times“的字体中。试图更改其他用户建议的所有图形的默认字体(set(0,'DefaultAxesFontName','scrbook')
)也不会产生预期的效果。
创建的图形
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_1.jpg','Resolution',600)
是在正确的字体,但有规律的图像。创建的图形
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_1.pdf','Resolution',600,'ContentType','vector')
是在错误的字体,但以所需的PDF矢量图形格式。
谢谢您一直鼓励我!
致以良好的问候,丁满
发布于 2020-04-27 18:30:18
因此,在考虑了一段时间后,我放弃了使用exportgraphics函数的想法。可能它确实有一个错误,因为它是首次在Matlab 2020 a中引入的。我接着使用了一个名为matlab2tikz的函数,它可以在这里下载:
https://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
该函数可以将图形保存为矢量图形,并使用\input命令将其包含到LaTeX中(请参阅本文末尾的代码)。使用中的字体将是LaTeX (计算机现代罗马)中的默认字体,这是我最终想要实现的。详情见:
https://www.youtube.com/watch?v=dg7z3bs-eA8
(不需要懂德语就能理解视频)
我使用的最后一个Matlab代码是:
gomatlab2tikz = true
figure('units','centimeters','position',[0 0 15.5 10.333])
plot(Zeit3,Temperatur3,'LineWidth',2)
grid on
title('Temperatur-Messprogramm für Messreihe 3')
xlabel('Zeit [min]') %Zeit [min]
ylabel('Temperatur [°C]') %Temperatur [°C]
xlim([0 150])
ylim([0 400])
xticks(linspace(0,150,16))
yticks(linspace(0,400,21))
set(gca,'FontSize',11)
if gosave == true
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_3.jpg','Resolution',150)
exportgraphics(gcf,'Temperatur_Messprogramm_Messreihe_3.pdf','Resolution',150,'ContentType','vector')
end
if gomatlab2tikz == true
matlab2tikz('Temperatur_Messprogramm_Messreihe_3.tikz')
end
至少在我的例子中,Matlab显示的数字不需要以厘米为单位来校正大小。但是,如果通过\ LaTeX命令导入LaTeX文件,则图的维度将是正确的。对于进一步改进的布局,可以使用\resizebox命令。
\begin{figure}[h]
\centering
\resizebox{1.00\linewidth}{!}{\input{Figures/Versuche/Temperatur_Messprogramm_Messreihe_1.tikz}}
\caption{Temperatur Messprogramm Messreihe 1}
\label{Temperatur_Messprogramm_Messreihe_1}
\end{figure}
https://stackoverflow.com/questions/61428282
复制相似问题