how to create a numeric tick label offset

조회 수: 10 (최근 30일)
Michael Ilewicz
Michael Ilewicz 2020년 1월 12일
댓글: Michael Ilewicz 2020년 1월 12일
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

채택된 답변

dpb
dpb 2020년 1월 12일
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
Michael Ilewicz
Michael Ilewicz 2020년 1월 12일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by