![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/649885/image.jpeg)
Scientific notation at y-axis with "ax.YAxis.Exponent"
조회 수: 26 (최근 30일)
이전 댓글 표시
I want to change the notation of the log y-axis:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/649695/image.png)
Here is an example code, which doesn't work:
y = [0.1 0.3 0.5 1];
figure(1),
plot(y)
yticks([0.1 0.5 1])
set(gca,'yscale','log')
ax = gca;
ax.YAxis.Exponent = 2
I found out that exponent notation doesn't work when yticks is used in conjunction with logarithmic scaling.
Any ideas???
댓글 수: 0
채택된 답변
dpb
2021년 6월 11일
Well, here's a crude first pass...
expn=floor(log10(yticks));
mant=yticks./10.^(expn);
lbls=cellstr(num2str([mant;expn].','%d*10^{%d}'));
lbls=strrep(lbls,'1*','')
lbls =
3×1 cell array
{'10^{-1}' }
{'5*10^{-1}'}
{' 10^{0}' }
>>
Then
yticklabels(lbls)
produces
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/649885/image.jpeg)
Salt to suit; no guarantees on how general will turn out to be...
댓글 수: 13
Walter Roberson
2021년 6월 14일
round. I did not want to assume that log10(0.001) was guaranteed to be exactly -3
추가 답변 (1개)
dpb
2021년 6월 11일
I don't see a user-settable format to force the notation (although I didn't use Yair's getundoc to poke) with arbitrary tick values but
yticks(10.^(-1:1))
will trigger redrawing with the desired notation.
It's having intermediate tick labels that causes the switch.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!