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

纵饮孤独 提交于 2019-12-18 06:18:35

问题


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 boldface?


回答1:


You could also overlay your "original" axis with a second one. On the second you configure the ticks bold. Together with linkaxes you maintain proper zoom behavior.




回答2:


Though I can't tell if it wasn't possible in the past, but nowadays (at least from R2014b) one could just use tex markup:

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




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/9169871/putting-certain-tick-labels-in-boldface-but-not-all-of-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!