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 日
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 で Grid Lines, Tick Values, and Labels についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
