如何解决MATLAB:如何在将图形打印到文件时为轴上的刻度定义 FontSize
我目前正在为我正在编写的应用开发图形生成工具。 在这方面,我试图更改轴上刻度的大小,但每次保存图形时,刻度的字体大小都会更改为默认值。 有没有办法防止这种情况? 代码如下:
F=figure('PaperPositionMode','manual','visible',false);
AX = gca;
% PLOT SOME STUFF (omitted here,since no relevance)
F.Resize = 'off';
F.Units = 'points';
F.PaperUnits = 'points';
AX.Units = 'points';
AX.Clipping = 'on';
AX.DataAspectRatioMode = 'auto';
AX.PositionConstraint = 'innerposition';
AX.FontSizeMode = 'manual';
% CHANGE PROPERTIES OF AX AND F
AX.XAxis.FontSize = 32;
% When executing next line,the font size of the ticks on the XAxis will change back to 10.
print(F,'CurrentFigure.png','-dpng','-r0');
% Changing AX.FontSize will not solve the problem.
% Changing interpreter will not solve the issue.
% Changing renderer will not solve the issue.
基本上我已经阅读了图形类、轴类和数字标尺类的每一个属性。将图形保存到文件时,我找不到任何保持刻度字体大小的选项。 如果我使用 exportgraphics (https://se.mathworks.com/help/matlab/ref/exportgraphics.html) 函数而不是打印函数,刻度大小保持不变。但是 exportgraphics 裁剪图像,在这种情况下完全破坏了程序的目的。所以我不能使用那个功能。
这是一个会产生所描述错误的小脚本。
% Figure Parameters
FigWidth = 2212; % Outer position
FigHeight = 1030; % Outer position
% Generate some data:
x = 0:0.1:2*pi;
y = cos(x);
yy = sin(x);
% Create figure
f = figure;
ax = axes;
f.Resize = 'off';
f.Units = 'points';
f.PaperUnits = 'points';
ax.Units = 'points';
ax.Clipping = 'on';
ax.DataAspectRatioMode = 'auto';
ax.FontSizeMode = 'manual';
ax.PositionConstraint = 'innerposition';
f.PaperPositionMode = 'auto';
f.OuterPosition = [100 100 FigWidth FigHeight]*72/96;
f.PaperPosition = [100 100 FigWidth FigHeight]*72/96;
ax.InnerPosition = [150 150 FigWidth-325 FigHeight-320]*72/96;
% Plot shizzle
plot(ax,x,y)
yyaxis right
plot(ax,yy)
yyaxis left
legend(ax)
ax.XGrid = 'on';
ax.XMinorGrid = 'on';
ax.YGrid = 'on';
ax.YMinorGrid = 'on';
% Change figure parameters
xlim([x(1) x(end)])
ax.XAxis.Label.String = 'X-Axis';
ax.YAxis(1).Label.String = 'Y-Axis';
ax.YAxis(2).Label.String = 'YY-Axis';
ax.YAxis(2).Label.Color = ax.YAxis(1).Label.Color;
ax.Title.String = 'Title';
LabelFontsize = 32;
ax.Title.FontSize = 32;
TicsFontSize = 30;
ax.Legend.FontSize = 30;
ax.XAxis.Label.FontSize = LabelFontsize;
ax.YAxis(1).Label.FontSize = LabelFontsize;
ax.YAxis(1).FontSize = TicsFontSize;
ax.YAxis(2).FontSize = TicsFontSize;
ax.XAxis.FontSize = TicsFontSize;
ax.YAxis(2).Label.FontSize = LabelFontsize;
pause(2)
print(f,'-r0');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。