Insert xticks in bold in existing xticks
15 views (last 30 days)
Show older comments
Hi,
I would like to make some change to the xticks of my plot without doing it manually.
So far i'm changing xticks of certain values by a text with :
names = {'text1'; 'text2'; 'text3'};
plot(...
set(gca,'xtick',[position1, position2, position3],'xticklabel',names)
The downside is that now I only have those 3 texts displaying in the x axis. I would like to have the default ticks PLUS those texts at those positions (in bold if possible). And just erase default ticks that are at those 3 positions.
Example if I have on the x axis the labels:
1, 2, 3, 4, 5, 6, 7, 8
I would like to have :
1, 2, text1, 4, 5, text2, 7, text3
How can I do this?
0 Comments
Answers (1)
dpb
on 5 Sep 2018
You've got to write the same number of tick labels as ticks and place the non-automatic text in the locations desired, explicitly. There's not sufficient syntax to write a portion of the 'XTickLabel' array alone.
hAx=axes; % make an axes to play with
xlim([1 8]) % set limits
xlbl=xticklabels; % retrieve default labels
ix=[3 6 8]; % define those to change
for i=1:length(ix) % make up the new ones for those locations...
xlbl(ix(i))={num2str(i,'\\bfText%d')};
end
xticklabels(xlbl) % and write them back.
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!