一次但独立地控制子图字体属性
Controlling subplot font properties at once but independently
我正在尝试以独立于其他字体属性的方式控制子图标题的属性,同时使用乳胶作为解释器(我认为最后一部分不相关,但以防万一)。这是一个示例代码:
% Figure handle
fig1 = figure;
% Subplot 1
subplot(2,1,1)
plot(rand(100,1))
xlabel('$x$ label')
ylabel('$y$ label')
title('First subplot')
% Subplot 2
subplot(2,1,2)
plot(rand(100,1))
xlabel('$x$ label')
ylabel('$y$ label')
title('Second subplot')
% Setting global properties
set(findall(fig1,'-property','FontSize'),'FontSize',14)
set(findall(fig1,'-property','Interpreter'),'Interpreter','Latex')
set(findall(fig1,'-property','TickLabelInterpreter'),'TickLabelInterpreter','Latex')
执行此操作时,我可以设置轴标签、刻度标签和子图标题的大小和解释器。这使得标题与其他标题具有相同的样式 objects。
有没有办法独立控制标题属性,例如让它们稍微变大变粗,以便与轴标签轻松区分?
如果只是想让标题变大,可以在调用title
命令时设置:
title('First subplot', 'FontSize', 14, 'FontWeight', 'bold')
如果你想更好地控制个人的字体大小 objects,你必须存储轴句柄(在创建子图时创建):
ax1 = subplot(211)
ax2 = subplot(212)
% set the properties of the title:
ax1.Title.FontSize = 14;
% set the properties of the XAxis:
ax1.XAxis.FontSize = 7;
要查看您可以更改哪些设置,只需调用命令中的句柄 window,这将为您提供更多详细信息:
>> ax1.Title
ans =
Text (First subplot) with properties:
String: 'First subplot'
FontSize: 14
FontWeight: 'bold'
FontName: 'Helvetica'
Color: [0 0 0]
HorizontalAlignment: 'center'
Position: [50.0001 1.0139 0]
Units: 'data'
如果要设置图中不同轴(子图)中标题的属性,可以将轴存储在元胞数组中:
ax = {subplot(211), subplot(212)};
plot(ax{1}, rand(100,1));
plot(ax{2}, rand(100,1));
for i=1:numel(ax)
ax{i}.Title.Fontsize = 14;
end
为了它的价值,我必须通过设置以下 "global" 属性(放在上面示例的末尾)来解决这个问题:
% Setting global properties
set(findall(fig1,'-property','Interpreter'),'Interpreter','latex')
set(findall(fig1,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex')
set(findall(fig1,'-property','Title'),'FontSize',14)
set(findall(fig1.Children,'-property','TitleFontSizeMultiplier'),'TitleFontSizeMultiplier',1.8)
有几点需要注意。图形句柄中的 属性 Children.TitleFontSizeMultiplier
可将您拥有的任何内容缩放为 FontSize
。但是,规范 FontSize
不能放在 Interpreter
之前,因为这似乎会锁定任何进一步的字体大小规范。
如果在使用latex
解释器时需要加粗,需要直接在标题中指定:title('\textbf{First subplot}')
。在normal
和bold
之间更改属性 Children.TitleFontWeight
似乎没有任何效果。
句柄数组上的 set
instruction can be applied to an array of graphic handle, so if you want to modify properties of all your titles, just gather their handles in an array first, then use the set
命令。
所以在你的例子中,替换你的
% ...
title('First subplot')
% ...
title('Second subplot')
% ...
作者:
% ...
ht(1) = title('First subplot')
% ...
ht(2) = title('Second subplot')
% ...
您现在拥有标题数组 ht
。现在批量修改它们,不修改任何其他内容:
set( ht , 'FontSize',18, 'FontWeight','bold')
同样,您可以重新组合其他 objects 的句柄以一次性分配它们的属性:
% build a collection of xlabel array
hxlabel = [hax(1).XLabel hax(2).XLabel] ;
% Set their label and interpreter all at once
set( hxlabel , 'String' , '$x$ label' , 'Interpreter','Latex' )
这将对所有子图应用相同的 xlabel
,并同时将它们的解释器设置为乳胶。
同样的推理可以应用于 ylabel
或许多 objects 中的任何其他常见 属性。
我正在尝试以独立于其他字体属性的方式控制子图标题的属性,同时使用乳胶作为解释器(我认为最后一部分不相关,但以防万一)。这是一个示例代码:
% Figure handle
fig1 = figure;
% Subplot 1
subplot(2,1,1)
plot(rand(100,1))
xlabel('$x$ label')
ylabel('$y$ label')
title('First subplot')
% Subplot 2
subplot(2,1,2)
plot(rand(100,1))
xlabel('$x$ label')
ylabel('$y$ label')
title('Second subplot')
% Setting global properties
set(findall(fig1,'-property','FontSize'),'FontSize',14)
set(findall(fig1,'-property','Interpreter'),'Interpreter','Latex')
set(findall(fig1,'-property','TickLabelInterpreter'),'TickLabelInterpreter','Latex')
执行此操作时,我可以设置轴标签、刻度标签和子图标题的大小和解释器。这使得标题与其他标题具有相同的样式 objects。
有没有办法独立控制标题属性,例如让它们稍微变大变粗,以便与轴标签轻松区分?
如果只是想让标题变大,可以在调用title
命令时设置:
title('First subplot', 'FontSize', 14, 'FontWeight', 'bold')
如果你想更好地控制个人的字体大小 objects,你必须存储轴句柄(在创建子图时创建):
ax1 = subplot(211)
ax2 = subplot(212)
% set the properties of the title:
ax1.Title.FontSize = 14;
% set the properties of the XAxis:
ax1.XAxis.FontSize = 7;
要查看您可以更改哪些设置,只需调用命令中的句柄 window,这将为您提供更多详细信息:
>> ax1.Title
ans =
Text (First subplot) with properties:
String: 'First subplot'
FontSize: 14
FontWeight: 'bold'
FontName: 'Helvetica'
Color: [0 0 0]
HorizontalAlignment: 'center'
Position: [50.0001 1.0139 0]
Units: 'data'
如果要设置图中不同轴(子图)中标题的属性,可以将轴存储在元胞数组中:
ax = {subplot(211), subplot(212)};
plot(ax{1}, rand(100,1));
plot(ax{2}, rand(100,1));
for i=1:numel(ax)
ax{i}.Title.Fontsize = 14;
end
为了它的价值,我必须通过设置以下 "global" 属性(放在上面示例的末尾)来解决这个问题:
% Setting global properties
set(findall(fig1,'-property','Interpreter'),'Interpreter','latex')
set(findall(fig1,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex')
set(findall(fig1,'-property','Title'),'FontSize',14)
set(findall(fig1.Children,'-property','TitleFontSizeMultiplier'),'TitleFontSizeMultiplier',1.8)
有几点需要注意。图形句柄中的 属性 Children.TitleFontSizeMultiplier
可将您拥有的任何内容缩放为 FontSize
。但是,规范 FontSize
不能放在 Interpreter
之前,因为这似乎会锁定任何进一步的字体大小规范。
如果在使用latex
解释器时需要加粗,需要直接在标题中指定:title('\textbf{First subplot}')
。在normal
和bold
之间更改属性 Children.TitleFontWeight
似乎没有任何效果。
句柄数组上的 set
instruction can be applied to an array of graphic handle, so if you want to modify properties of all your titles, just gather their handles in an array first, then use the set
命令。
所以在你的例子中,替换你的
% ...
title('First subplot')
% ...
title('Second subplot')
% ...
作者:
% ...
ht(1) = title('First subplot')
% ...
ht(2) = title('Second subplot')
% ...
您现在拥有标题数组 ht
。现在批量修改它们,不修改任何其他内容:
set( ht , 'FontSize',18, 'FontWeight','bold')
同样,您可以重新组合其他 objects 的句柄以一次性分配它们的属性:
% build a collection of xlabel array
hxlabel = [hax(1).XLabel hax(2).XLabel] ;
% Set their label and interpreter all at once
set( hxlabel , 'String' , '$x$ label' , 'Interpreter','Latex' )
这将对所有子图应用相同的 xlabel
,并同时将它们的解释器设置为乳胶。
同样的推理可以应用于 ylabel
或许多 objects 中的任何其他常见 属性。