# Y axis in scientific form

조회 수: 41 (최근 30일)
sani 2020년 5월 27일
댓글: sani 2020년 5월 28일
Hello,
I want to plot Y axis in the scientific form and not in engineering form (es 1E4 and not 10^4), si it possible?

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

### 채택된 답변

Tommy 2020년 5월 27일
How does this work for you?
ax = axes;
plot(ax, 1:10, (1:10).^10)
% get rid of 'x 10^N' in corner
ax.YAxis.Exponent = 0;
% get rid of 'x 10^N' formatting in individual labels
ytickformat(ax, '%f')
% get the labels
yticklabels = ax.YTickLabel;
% for each one, reformat to 'E+N' notation using sprintf
for ii = 1:numel(yticklabels)
yticklabels{ii} = sprintf('%.0E', str2double(yticklabels{ii}));
end
% reassign the labels
ax.YTickLabel = yticklabels;
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Tommy 2020년 5월 27일
편집: Tommy 2020년 5월 27일
The above code won't work for axes scaled logarithmically. This should work for either case (it's probably better, now that I think about it):
ax = axes('YScale', 'log', 'NextPlot', 'add');
plot(ax, 1:10, (1:10).^10)
% get the ticks
yticks = ax.YTick;
yticklabels = cell(numel(yticks),1);
% for each one, create a corresponding label with 'E+N' notation using sprintf
for ii = 1:numel(yticks)
yticklabels{ii} = sprintf('%.0E', yticks(ii));
end
% assign the labels
ax.YTickLabel = yticklabels;
(edit) For more control over the exact format:
ax = axes('YScale', 'log', 'NextPlot', 'add');
plot(ax, 1:10, (1:10).^10)
% get the ticks
yticks = ax.YTick;
yticklabels = cell(numel(yticks),1);
% for each one, create a corresponding label with 'EN' notation using sprintf
for ii = 1:numel(yticks)
e = floor(log10(yticks(ii)));
b = yticks(ii) / 10^e;
yticklabels{ii} = sprintf('%dE%d', b, e);
end
% assign the labels
ax.YTickLabel = yticklabels;
sani 2020년 5월 28일
thank you, this is exactly what I wanted!

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

### 추가 답변 (1개)

Walter Roberson 2020년 5월 27일
If you are referring to the scale factor that sometimes get put up near the top of the Y axes, then the answer is that there is no known way to change the format of it. There are only ways to enable it or disable it or to change the basic power (e.g., you could force it to be 10^3 in which case the automatic axes labels could be in the tens).
In the case where you want something like that but what is provided automatically does not meet your needs, then you will probably need to text() what you want into place. You might need to set the axes 'clipping' to 'off'
It just might be possible to locate an internal text() object used for the exponent and modify it; that would take some investigation.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
sani 2020년 5월 28일
thanks!

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

### 카테고리

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