Move positive and negative y ticks in plot in alignment

조회 수: 6 (최근 30일)
DavidL88
DavidL88 2022년 7월 21일
댓글: Star Strider 2022년 7월 22일
In my plot below I want to align the yticks to the right so that the numbers are aligned vertically. The -3 and -6 are closer to the axis line as they have a minus first whereas the 0, 3 and 6 have a space after them. I tried putting a space prior to these three digits so the numbers are aligned but didn't work. Is there a way to do this or make these ticks alig to the right rather than left?
ylim([-6.3 6.3])
yticks([-6 -3 0 3 6]);

채택된 답변

Star Strider
Star Strider 2022년 7월 21일
Experiment with the TickLabelFormat property of the NumericRuler Properties.
figure
plot(1:10, randn(1,10))
ylim([-6.3 6.3])
yticks([-6 -3 0 3 6]);
Ax = gca;
Ax.YAxis.TickLabelFormat = '%3.0f';
.
  댓글 수: 6
DavidL88
DavidL88 2022년 7월 22일
I fixed this thanks.
Another way to get a handle is;
ytickformat('%3.0f');
Star Strider
Star Strider 2022년 7월 22일
My pleasure!
That was essentially my original approach. There are several ways to set the tick format, and I chose one that I was certain would work.
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by