formatting axes for a plot

1 次查看(过去 30 天)
Hello,
Why whenever I do this to format the x-axis to be between 0-6 and then type (x10^4) it does not show the x-ticks on the x-axis:
xVals = 0:.6:6;
set(gca,'xtick',xVals);
expVal = 4; %exponent you want
set(gca,'XTickLabel',sprintf('%2.1f|',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')

采纳的回答

José-Luis
José-Luis 2013-1-1
If all you want to do is to add the annotation in your plot, you don't need to add the 'XTicks'.
You could just add this section to your original code:
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')
  5 个评论
José-Luis
José-Luis 2013-1-2
x = 0:6000:60000;
y = randn(numel(x),1);
plot(x,y,'b-o')
xVals = x;
set(gca,'xtick',xVals);
expVal = 4; %exponent you want
set(gca,'XTickLabel',sprintf('%2.1f|',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')

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-1-1
Add to your code
set(gca,'xlim',[0 6])
  4 个评论
Sam Alex
Sam Alex 2013-1-1
Something happens when I add this to my code, it removes all markers and the look of the original plot
Azzi Abdelmalek
Azzi Abdelmalek 2013-1-1
Post the code which is making a problem

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by