グラフのy軸の目盛り​ラベルにて、整数部の​表示桁数を指定する方​法について

조회 수: 15 (최근 30일)
拓磨 佐藤
拓磨 佐藤 2023년 11월 15일
댓글: Dyuman Joshi 2023년 11월 15일
下記のようなグラフを表示するコードで、大きな整数値だと指数表示になって細かい値が見れなくなってしまいます。
「1x10^5」のように指数表示せず、「100001 100002 100003 100004 100005」という値をそのまま縦軸に表示する方法を知りたいです。
小数部の精度はytickformat関数で指定できますが、整数部の表示桁数を指定する方法などはあるのでしょうか。
x = 1:5;
y = [100001 100002 100003 100004 100005];
plot(x, y);
ytickformat('%d');

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 11월 15일
편집: Dyuman Joshi 2023년 11월 15일
The ticklabels are stored as the mantissa and the exponent is stored as the property of the corresponding axis (see below).
So, changing the tick format only changes the values of the mantissa.
Solution - Change the exponent of the y-axis to 0
x = 1:5;
y = [100001 100002 100003 100004 100005];
labels = yticklabels
labels = 11×1 cell array
{'0' } {'0.1'} {'0.2'} {'0.3'} {'0.4'} {'0.5'} {'0.6'} {'0.7'} {'0.8'} {'0.9'} {'1' }
plot(x, y)
ax = gca;
ax.YAxis.Exponent = 0;
%Check labels after modification
labels = yticklabels
labels = 9×1 cell array
{'100001' } {'100001.5'} {'100002' } {'100002.5'} {'100003' } {'100003.5'} {'100004' } {'100004.5'} {'100005' }
  댓글 수: 2
拓磨 佐藤
拓磨 佐藤 2023년 11월 15일
Great! Thank you for your answer.
Dyuman Joshi
Dyuman Joshi 2023년 11월 15일
You are welcome!

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

추가 답변 (0개)

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!