format the y tick labels
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
hello,
How can I format the y tick labels in e-notation? (note: I entered those exact labels as numbers in the form I want them to appear) but I still want them to appear in e-notation. Is there a way to do this when I edit the figure properties?
Thanks
채택된 답변
Sara
2014년 5월 6일
0 개 추천
If you want to change the format of the y-axis:
y = get(gca,'ytick');
yy = cell(numel(y),1);
for i = 1:numel(y)
yy{i}=sprintf('%10.3e',y(i)); %%CHOOSE PRECISION
end
set(gca,'yticklabel',yy)
댓글 수: 16
Seldeeno
2014년 5월 8일
Thanks...but how can I use the "10^x" notation instead?
Sara
2014년 5월 8일
You can't automatically. You'll have to replace the ticks with the text command. This may do it for you:
Seldeeno
2014년 5월 8일
This is very complicated for non-programmers. All I need is just how to print on the y-scale, values like 10^-20, 10^10 and so on
Thanks
Sara
2014년 5월 8일
Are you using plot or semilogy or loglog to plot your data?
Seldeeno
2014년 5월 8일
I am using plot
Sara
2014년 5월 8일
can you attach a sample of data or a plot of your data?
Seldeeno
2014년 5월 8일
This is the snippet I have. In this part, the data might take values that go from 10^-10 to 10^4 and I want the ytick to show such scale (although the code below is been uniformed).
clc
clear
axis([0 6 0 9])
grid on
hold on
% Initially, the list of points is empty.
xy = [];
n = 0;
% Loop, picking up the points.
disp('Left mouse button picks points.')
disp('Right mouse button picks last point.')
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'ro');xx(n+1)=xi;yy(n+1)=yi;
n = n+1;
xy(:,n) = [xi;yi];
end
% Interpolate with a spline curve and finer spacing.
t = 1:n;
ts = 1: 0.1: n;
xys = spline(t,xy,ts);
% Plot the interpolated curve.
plot(xys(1,:),xys(2,:),'b-');
hold off
Sara
2014년 5월 8일
The issue is that if you use "plot" and the data range is that large, you won't see anything 1 or 2 order of magnitude lower that the maximum value. Try adding at the end and see if it solves your problem:
y = get(gca,'ytick');
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('%.0f%s10^%.0f',y ./ 10.^floor(log10(y)),char(215),floor(log10(y))))
you need to download tick2text
Seldeeno
2014년 5월 8일
I thank you for your continuous help. My last question is that, for one of the figures, I want to show how data is behaving even on a small scale. Now I can normalize data but I want to enforce placing just two values on the y-axis: Just 10^-5 and 10^-1. How can I do this using your last hint?
Sara
2014년 5월 8일
It needs to be modified for negative numbers so that you have something like 10^-^number. otherwise the number won't be at the exponent. Is that clear enough?
Seldeeno
2014년 5월 8일
forgive me for asking more, but as a non-programmer, I thought it would be easy (although tricky) to have such thing possible. What thing do I need to modify?
Thanks
Sara
2014년 5월 8일
This will work only if your y axis is always < 1:
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('%.0f%s10^-^%.0f',y ./ 10.^floor(log10(y)),char(215),-floor(log10(y))))
Seldeeno
2014년 5월 8일
Probably you didnt get my point, as all I wanted was to force that I print on the y-axis just two values like: 10^0 and 10^5 (just as ytick). Can I just do this?
Seldeeno
2014년 5월 8일
I made a progress with this code, but why are the yticks it overlapping the y-axis?
ax = subplot(1,1,1);
plot(x,y);
title('Modified tick marks');
set(ax, 'ylim', [0 9]);
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('10^%.0f',y))
hx = getappdata(ax, 'YTickText');
set(hx, 'Rotation', 0, 'fontsize', 8, 'horiz', 'left');
Sara
2014년 5월 9일
It's the:
'horiz', 'left'
command, try taking it away. Note, you may want to do:
set(gca,'fontsize',8)
so that all the ticks are of the same size.
Seldeeno
2014년 5월 9일
Sara, you are great. Thank you for your help :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
