在Matlab 2017a中将xticklabel设为粗体和斜体

问题描述 投票:0回答:1

我正在尝试将xticklabels(单元格数组)设置为粗体。大多数先前的命令不起作用。

h=figure(1);
gca.XAxis.TickLabel='\bf{%g}'  % xticklabel is preassigned in box plot as text from cell array {'AB','CD','EF','GH'}.

上面命令中的某些修改会产生错误,例如-“使用set时出错,无法从struct转换为double。”请建议进行修改,如果可能的话,建议使用相同的默认属性设置器。

matlab plot graphics properties label
1个回答
0
投票

以下将使XTickLabels为粗体:

fig = figure(1); 
ax = axes;           % or: ax = gca;
plot(rand(10));
ax.XTickLabel = cellfun(@(a) ['\bf{' a '}'], ax.XTickLabel, 'UniformOutput',false);

您无法使用与gca相同的方式来使用ax,因为gca是将返回当前轴的函数,并且无法对函数进行点索引。

如果要使用set(和get),可以按以下步骤进行,

currentLabels = get(gca, 'XTickLabel');
set(gca, 'XTickLabel', cellfun(@(a) ['\bf{' a '}'], currentLabels, 'UniformOutput',false));

0
投票

您应该将FontWeight对象的XAxis属性更改为'bold',例如:

figure();
set(get(gca, 'XAxis'), 'FontWeight', 'bold');

结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.