一次但独立地控制子图字体属性

时间:2018-11-21 12:24:25

标签: matlab matlab-figure

在使用乳胶作为解释器时,我试图以与其他字体属性无关的方式来控制子图标题的属性(我不认为这最后一部分是相关的,但以防万一)。这是示例代码:

% 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')

执行此操作时,可以为轴标签,刻度标签和子图标题设置大小和解释程序。这使标题具有与其他对象相同的样式。

是否有一种方法可以独立控制标题属性,例如使它们稍大一些和大胆一些,以便可以轻松地将它们与轴标签区分开?

3 个答案:

答案 0 :(得分:2)

如果只想扩大标题,可以在调用Do While xExcelFile <> "" Select Case True 'go to next loop if the selected file and this workbook has the same name Case xExcelFile = xWname GoTo NextLoop Case GetPattern(newFileName) = "^([B]\d{3}\w{1,})" 'file is pattern 1 Case GetPattern(newFileName) = "^\d*\.\d{4}\w*" 'file is pattern 2 命令时进行设置:

title

如果要更多地控制单个对象的字体大小,则必须存储轴句柄(在创建子图时创建):

title('First subplot', 'FontSize', 14, 'FontWeight', 'bold')

要查看可以更改的设置,只需在命令窗口中调用手柄,即可为您提供更多详细信息:

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;

如果要在图形的不同轴(子图)中设置标题的属性,则可以将轴存储在单元格数组中:

>> 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'

答案 1 :(得分:1)

set指令可以应用于图形手柄数组,因此,如果要修改所有标题的属性,只需先将它们的手柄收集到数组中,然后使用set命令在句柄数组上。

因此在您的示例中,替换您的

% ...
title('First subplot')
% ...
title('Second subplot')
% ...

作者:

% ...
ht(1) = title('First subplot')
% ...
ht(2) = title('Second subplot')
% ...

您现在有了标题的句柄ht数组。现在,可以批量修改它们,而无需进行其他任何修改:

set( ht , 'FontSize',18, 'FontWeight','bold')

类似地,您可以重新组合其他对象的句柄以一次性分配其属性:

% 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或许多对象上的任何其他公共属性都可以应用相同的推理。

答案 2 :(得分:0)

对于它的价值,我必须通过设置以下“全局”属性(放在上面的示例的末尾)来解决:

<?php
$temp=$_POST['prod'];
echo $temp;
?>

没什么要注意的。图句柄中的属性% 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}')Children.TitleFontWeight之间更改属性normal似乎没有任何效果。