使xticklabels加粗

我正在尝试使xticklabels(单元格数组)加粗。我尝试了一些变体:

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

但是,大多数错误都会导致

之类的错误
Error using set,Conversion to double from struct is not possible

请针对上述问题提出解决方案,并在可能的情况下为此效果提供默认属性设置器。

我正在使用MATLAB 2017a。

zhangjiany2929 回答:使xticklabels加粗

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

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

结果:

enter image description here

,

以下内容将使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是将返回当前轴的函数,并且无法对函数进行点索引。 / p>

如果您想使用set(和get),可以按照以下步骤进行操作,

currentLabels = get(gca,'XTickLabel');
set(gca,'XTickLabel',cellfun(@(a) ['\bf{' a '}'],currentLabels,false));
本文链接:https://www.f2er.com/3166379.html

大家都在问