Search code examples
matlabmatlab-figure

How to change font weight and size of some of xticklables matlab?


I want to change the font weight and size of some of the xticklables. For example xtick 3,7, and 8. So far I found how to do it one by one. is there a way to do them at once? here is an example to change xtick 3 font weight.

plot(1:10, rand(1,10))
ax = gca;
ax.XTickLabel{3} = ['\bf' ax.XTickLabel{3}];

Solution

  • You can use the cellfun function to generate the cell array of label strings and use the matlab array indexing to change some of the the elements of the XTickLabel property:

    plot(1:10, rand(1,10))
    ax= gca;
    i= [3 7 8]; % the indices of the tick labels to change
    ax.XTickLabel(i)= cellfun(@(s)['\bf ' num2str(s)],ax.XTickLabel(i),'UniformOutput',false);