Putting certain tick labels in boldface (but not all of them)?

后端 未结 4 1197
慢半拍i
慢半拍i 2020-12-19 10:45

In MATLAB I have a graph with some tick labels. I\'d like to visually emphasize a few of these labels, but not all of them. Is there a way to only put SOME tick labels in b

4条回答
  •  孤城傲影
    2020-12-19 11:13

    Tick labels are not individual objects. They belong to axes and their properties determined by axes.

    What you can do is to remove tick labels and replace them with text objects. In this case you can control the text properties.

    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

提交回复
热议问题