how to create a numeric tick label offset

7 views (last 30 days)
Hi, I have a plot with large numbers on the scale e.g.
384230 384231 284232
and I would like to only show the last two digits on my final plot and have an offset noted at the side of the axis, usually where the exponent is noted so that my final tick labels look like
30 31 32 .... +284200.
I know that this is possible because I had a plot once where I struggled to get rid of the automatic function but I have been looking for a solution way to long and I can't find the right Tag. I hope someone can lead me in the right direction

Accepted Answer

dpb
dpb on 12 Jan 2020
x=[384230 384231 284232 ...];
X0=384200; % offset value -- uses arbitrary origin
hL=plot(x-X0,y); % plot relative the offset so get desired tick labels range automagically
xl=xlim; yl=ylim; % retrieve x,y-axis limits
text(xl(end),0.95*yl(1),num2str(X0,'+%d'),'horizontalalign','right','verticalalign','top')
Salt postions to suit...just a guess. Lost access to license at least temporarily so can't test; air code...
  1 Comment
Michael Ilewicz
Michael Ilewicz on 12 Jan 2020
This works even better:
xl=xlim;
xlabelPos=get(get(gca, 'XLabel'), 'Position');
text(xl(end),xlabelPos(2),num2str(X0,'+%d GHz'),'HorizontalAlignment','right','VerticalAlignment','top');
thanks

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!