将某些刻度标签以粗体显示(但不是全部)?

时间:2012-02-07 01:32:01

标签: matlab plot matlab-figure

在MATLAB中,我有一个带有一些刻度标签的图表。我想在视觉上强调一些这些标签,但不是全部。有没有办法只将SOME刻度标签以粗体显示?

4 个答案:

答案 0 :(得分:5)

虽然我无法判断过去是否可能,但现在(至少从R2014b开始),人们可以使用tex标记:

plot(0:10,0:10);
h = gca;
h.XTickLabel = {'\bf \color{red} 0','2','\bf 4','6','\bf \color{red} 8','10',}

enter image description here

答案 1 :(得分:3)

刻度标签不是单个对象。它们属于轴,它们的属性由轴确定。

您可以做的是删除刻度标签并用文本对象替换它们。在这种情况下,您可以控制文本属性。

plot(magic(5))
xticks = get(gca,'XTick'); %# x tick positions
xlabels = cellstr(get(gca,'XTickLabel')); %# get the x tick labels as cell array of strings
set(gca,'XTickLabel',[]) %# remove the labels from axes
n = numel(xlabels);
yl = ylim;
idx1 = 1:2:n; %# 1st set of ticks
idx2 = 2:2:n; %# 2nd set
t1 = text(xticks(idx1),repmat(yl(1),numel(idx1),1), xlabels(idx1), ...
    'HorizontalAlignment','center','VerticalAlignment','top');
t2 = text(xticks(idx2),repmat(yl(1),numel(idx2),1), xlabels(idx2), ...
    'HorizontalAlignment','center','VerticalAlignment','top');
set(t2,'FontWeight','bold') %# make the 2nd set bold

Bold ticks example

答案 2 :(得分:2)

您还可以使用第二个轴覆盖“原始”轴。在第二步,你配置刻度线粗体。与链接一起保持适当的缩放行为。

答案 3 :(得分:0)

%% creat a new control vector, like here I want to make some special labels
as bold red. 

control_vector = cell(length(the_origional_Xlabels), 1);
control_vector(index) = {'\bf \color{red} '}; 

%% the put string cat the control vector and the original xlables
new_labels = control_vector, protease_universal_sorted));
xticks(1:length(the_the_origional_Xlabels));
xticklabels(new_labels)