force a scientific notation format
58 ビュー (過去 30 日間)
古いコメントを表示
hi,
when i use this code, instead of forcing it to give me the x-axis as: 0,1,2,...,10 then x10^3 (3 is a superscript) it gives me the numbers as 1000,2000,...and so on...any idea?
x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
set(gca,'xtick',0:0.1e4:0.1e5);
4 件のコメント
José-Luis
2012 年 12 月 25 日
編集済み: José-Luis
2012 年 12 月 25 日
As a general rule, people will be more inclined to answer a well posed, clear question. When I see unedited text posed as a question I often tend to ignore it, unless it is very short (like yours was). Other contributors might be more dedicated, but I think a nice presentation increases your chances for an answer.
neo
2012 年 12 月 25 日
編集済み: neo
2012 年 12 月 25 日
I think following link may help:
I also feel this is a problem. The obvious solution would have been to edit XTickLabel using latex/tex interpreter. But Matlab help clearly states that one can not use latex/tex for axis tick labels. So solutions like above replaces them by text objects and then use latex/tex interpreter.
I Wonder how matlab does it for log-log or semilog plots or when axis limit exceeds about 10^5 or similar cases.
採用された回答
José-Luis
2012 年 12 月 25 日
編集済み: José-Luis
2012 年 12 月 25 日
x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
xVals = 0:0.1e4:0.1e5;
set(gca,'xtick',xVals);
set(gca,'XTickLabel',sprintf('%2.0e|',xVals));
The last line in the previous snippet sets the format for your XTickLabels. For more information on other formats:
doc sprintf
EDIT Exponent should appear at the right of the X-axis
x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
xVals = 0:0.1e4:0.1e5;
set(gca,'xtick',xVals);
expVal = 3; %exponent you want
set(gca,'XTickLabel',sprintf('%2.0f|',xVals./(10^expVal)));
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')
4 件のコメント
その他の回答 (1 件)
Jonathan Epperl
2012 年 12 月 25 日
Afaik that's not possible, since the tick labels aren't like normal text objects in that they support a subset of latex commands. I recommend tick2text ( http://www.mathworks.com/matlabcentral/fileexchange/16003-tick2text-create-easy-to-customize-tick-labels ) from the FEX. Once you have it on your Matlab path:
x = 10.^(1:10);
plot(x,x)
g = gca;
tick2text(g,'axis','x')
h = getappdata(g,'XTickText')
for i=1:numel(h), set(h(i),'String',num2str(i,'10^%d')); end
1 件のコメント
José-Luis
2012 年 12 月 25 日
What do you mean it's not possible? You can set XTickLabel to whatever string you want, even if it has nothing to do with the numeric value. You can't use Latex as the interpreter though, I'll agree to that, but that's not relevant for what the op asked, if I understood correctly.
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!