Reputation: 467
I want to mark some special point on the x-axis of a matlab plot, and I'm satisfied with the rest automatic x-ticks that matlab produce. Therefore I do not want to change them, only to add this special xtick and xticklabel in the midst of them. What is the easiest way to do it in a matlab m-function?
Upvotes: 1
Views: 1899
Reputation: 1275
Try something like this:
plot(1:100);
ticks = get(gca,'XTick');
ticklabels = cellstr(get(gca,'XTickLabel'));
ticks(end+1) = pi;
ticklabels{end+1} = 'Pi';
[ticks,idx] = sort(ticks);
ticklabels = ticklabels(idx);
set(gca,'Xtick',ticks,'XTickLabel',ticklabels);
Upvotes: 2
Reputation: 146
plot(1:5,1:5)
marks = get(gca,'XTick');
marks = sort([marks,pi]);
set(gca,'XTick',marks);
There are some issues with scaleability, calling xlim, etc. but maybe it is good enough for your problem.
Upvotes: 0